Skip to content

Reject ZIP_FL_LOCAL|ZIP_FL_CENTRAL in zip_file_extra_field_get_by_id() - #565

Open
Nexory wants to merge 1 commit into
nih-at:mainfrom
Nexory:reject-both-lists-in-extra-field-get-by-id
Open

Reject ZIP_FL_LOCAL|ZIP_FL_CENTRAL in zip_file_extra_field_get_by_id()#565
Nexory wants to merge 1 commit into
nih-at:mainfrom
Nexory:reject-both-lists-in-extra-field-get-by-id

Conversation

@Nexory

@Nexory Nexory commented Aug 21, 2026

Copy link
Copy Markdown

Since 1.12 keeps local and central extra fields in separate lists, an extra
field index can no longer address both at once: the index is applied to each
list in turn and the first match wins, so fields behind that match are skipped.

With one local and two central fields of the same id:

count_extra_by_id  l / c / cl   ->  1 / 2 / 3
get_extra_by_id 0 cl            ->  local,      len 9
get_extra_by_id 1 cl            ->  central #1, len 16
get_extra_by_id 2 cl            ->  ZIP_ER_NOENT

The count reports three fields, but the first central one is not reachable at
any index, and index 1 returns a valid pointer to a different field rather than
an error. Addressing one list at a time still finds all three.

zip_file_extra_field_get() got a guard for exactly this in cbad2ba. The by_id
variant was not changed, so this adds the same guard there. Addressing a single
list is unchanged.

I looked at the rest of the family before assuming it was wider: the two count
functions take no index, so both lists are unambiguous for them, and
zip_file_extra_field_set() with both flags writes the field to both lists,
which is lossless. Only this one function needed the guard.

The behaviour is on main only, so no released version is affected. I built with
BUILD_DOC=OFF because the documentation step writes generated files back into
the source tree, which I mount read-only.

Since local and central extra fields are kept in separate lists, an extra
field index can not address both at once: it is applied to each list in turn,
so the first match wins and fields behind it are silently skipped. With one
local and two central fields of the same id, zip_file_extra_fields_count_by_id()
reports 3 while index 0 returns the local field, index 1 the second central
one, and index 2 ZIP_ER_NOENT. The first central field is not reachable at any
index, and index 1 returns a valid pointer to the wrong field rather than an
error.

Reject the combination the way zip_file_extra_field_get() already does.
Addressing a single list is unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant