adobe / adobe/XMP-Toolkit-SDK

Garbage after XMP in PNG files when XMP has shrunk

Open
#121 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
262
Forks
110
PR merge metrics
No merged PRs in 30d

Description

1. Add a large XMP block to a PNG file (using your tool of choice).
2. Replace it with a shorter XMP block using XMP Toolkit SDK.
3. Inspect the `iTXt` segment, e.g. with this Python-script:
```
from sys import argv, stdout
from PIL import Image

stdout.reconfigure(encoding='utf-8')

with Image.open(argv[1]) as img:
img.load()
text_data = getattr(img, "text", {})

if text_data:
for key, value in text_data.items():
if key == 'XML:com.adobe.xmp':
print(value)
```

Result: The `iTXt` segment size does not change, and there are garbage XMP fragments after the valid XMP.

This seems to be because `PNG_MetaHandler::UpdateFile()` only replaces the number of bytes taken up by the new XMP block in the `iTXt` segment and not the entire segment.

I will submit a PR with a proposed fix.

Kind Regards
Bjørn Thirud

Contributor guide

Open the contributing guide

Research direction

Start with PNG_MetaHandler::UpdateFile() and reproduce the reported steps using the provided Python script to inspect the iTXt segment. Compare the segment after replacing large XMP with shorter XMP; done means the segment reflects the shorter block without trailing garbage XMP fragments.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.