Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion SDMeta/Metadata/PngMetadataExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class PngMetadataExtractor
SkipBytes(fs, 4);
break;
case "tEXt":
case "iTXt":
var keywordValuePair = await ReadTextualData(fs, chunkLength);
SkipBytes(fs, 4); // Move past the current chunk CRC
yield return keywordValuePair;
Comment on lines 33 to 36
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 33 to 36
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.
Expand Down Expand Up @@ -80,7 +81,7 @@ private async static Task<string> ReadChunkType(Stream stream)
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
);
Comment on lines 85 to 90
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.
}

Expand Down
Loading