Repository navigation
Validate keywords and reject null bytes in text chunk fields - #738
Open
Ramya-9353 wants to merge 1 commit into
Open
Ramya-9353 wants to merge 1 commit into
Ramya-9353 wants to merge 1 commit into
Conversation
The keyword of tEXt/zTXt/iTXt and the language tag and translated keyword of iTXt are terminated by a null byte in the encoded chunk, so a null byte inside one of those values ended the field early and every field after it was read out of the remainder of the same string. Only the keyword length was checked before. Validate the keyword against the printable Latin-1 and spacing rules of the specification and reject a null byte in the two remaining iTXt fields, inside encode where the field layout is written.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Repro:
TEXtChunk::new("Author\0forged", "real")encodes to a chunk that decodes back as keywordAuthor, textforged\0real.ITXtChunk::new("Comment\0\0\0en\0Author\0Trusted Author", "the real text")decodes as keywordComment, language tagen, translated keywordAuthor, textTrusted Author\0\0\0\0\0the real text. A null byte inITXtChunk::language_tagortranslated_keywordshifts the following fields the same way.Cause: the three
EncodableTextChunk::encodeimpls checked only that the keyword is 1 to 79 bytes, and theiTXtlanguage tag and translated keyword were not checked at all, so a null byte ended its own field early and the bytes after it were read as the fields that follow.Fix: validate the keyword against the printable Latin-1 and spacing rules of 11.3.4.2 and reject a null byte in the language tag and translated keyword, in
encodewhere the field layout is written.A caller embedding externally supplied metadata ("Author", "Comment") therefore emitted chunks whose decoded fields it never asked for, with the genuine text hidden behind the injected null bytes, which is why the check belongs in the encoder rather than at each call site. Tests cover all four fields and fail on master. The
iCCPprofile name is length-checked only as well, but its one caller passes a constant, so I have left it.