Skip to content

add itext metadata support#491

Merged
jamesmoore merged 2 commits intomainfrom
add-itext-metadata-support
Mar 6, 2026
Merged

add itext metadata support#491
jamesmoore merged 2 commits intomainfrom
add-itext-metadata-support

Conversation

@jamesmoore
Copy link
Owner

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for extracting additional PNG textual metadata by recognizing the iTXt chunk type in the existing PNG metadata extraction pipeline.

Changes:

  • Treat iTXt chunks as textual metadata chunks alongside tEXt.
  • Adjust null-terminator trimming when parsing chunk payloads into (Key, Value) pairs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 32 to 36
case "tEXt":
case "iTXt":
var keywordValuePair = await ReadTextualData(fs, chunkLength);
SkipBytes(fs, 4); // Move past the current chunk CRC
yield return keywordValuePair;
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iTXt chunks do not have the same payload layout as tEXt (they include compression flag/method + language tag + translated keyword + possibly zlib-compressed UTF-8 text). Routing iTXt through ReadTextualData will yield incorrect values (and can include binary bytes/garbage). Add a dedicated ReadInternationalTextualData parser for iTXt (including optional zlib decompression) and call that from this switch case instead of reusing the tEXt logic.

Copilot uses AI. Check for mistakes.
Comment on lines 80 to 85
var dataString = buffer.BytesToString().TrimEnd(NullTerminator).Trim();
var nullIndex = dataString.IndexOf(NullTerminator);
return new (
nullIndex > -1 ? dataString.Substring(0, nullIndex) : string.Empty,
nullIndex > -1 && nullIndex + 1 < length ? dataString.Substring(nullIndex + 1).TrimEnd(NullTerminator) : string.Empty
nullIndex > -1 && nullIndex + 1 < length ? dataString.Substring(nullIndex + 1).Trim(NullTerminator) : string.Empty
);
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReadTextualData converts the entire chunk to a string and then trims null terminators. This breaks iTXt parsing because the bytes immediately after the keyword are binary (compression flag/method) and may legitimately be 0x00; Trim(NullTerminator) will drop those leading bytes and corrupt the payload. For iTXt, parse at the byte level (split on nulls for the keyword/language/translated keyword, then treat the remaining bytes as (optionally decompressed) UTF-8 text) rather than trimming nulls from a decoded string.

Copilot uses AI. Check for mistakes.
Comment on lines 32 to 36
case "tEXt":
case "iTXt":
var keywordValuePair = await ReadTextualData(fs, chunkLength);
SkipBytes(fs, 4); // Move past the current chunk CRC
yield return keywordValuePair;
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change adds iTXt handling, but the test suite only covers tEXt via latin1-pngtext.png. Add at least one PNG fixture containing an iTXt chunk (ideally both compressed and uncompressed variants) and a corresponding test assertion to prevent regressions in iTXt parsing/decompression.

Copilot uses AI. Check for mistakes.
@jamesmoore
Copy link
Owner Author

@copilot open a new pull request to apply changes based on the comments in this thread

Copy link
Contributor

Copilot AI commented Mar 6, 2026

@jamesmoore I've opened a new pull request, #492, to work on those changes. Once the pull request is ready, I'll request review from you.

@jamesmoore jamesmoore merged commit d6b3c67 into main Mar 6, 2026
5 checks passed
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.

3 participants