Repository navigation
Raise SyntaxError for non-numeric XBM #define values - #10319
Conversation
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
Hi. I'm not convinced this is unequivocally a bug. Could you explain why you think it is? I don't expect you encountered a file starting with "#define FOO bar" that didn't intended to be an XBM file or similar, so I think we have identified the image. |
|
I had the same problem too. I agree that This looks like a regression from the fix for CVE-2026-112901. Commit I tested Pillow 12.3.0, Pillow 13.0.0, and The valid XBM was created with Pillow: out = io.BytesIO()
Image.new("1", (8, 8), 0).save(out, "XBM")
data = out.getvalue()The 8-byte parser test was: parser = ImageFile.Parser()
for i in range(0, len(data), 8):
parser.feed(data[i:i + 8])
parser.close()With one partial block, the parser sees: The value has not arrived yet, but value = int(line.split().pop())This calls
try:
with io.BytesIO(self.data) as fp:
im = Image.open(fp)
except OSError:
passTherefore, it cannot keep the partial data and wait for the next block. The fix proposed in this PR #10319 should solve both cases: try:
value = int(line.split().pop())
except ValueError as e:
raise SyntaxError("not a XBM file") from eAfter applying the same fix locally, my test gave: So I think the non-numeric |
|
@LemonCondor I opened a PR on your fork to add |
Tests: Add regression test for XBM incremental parsing
|
Thanks for looking at this. To be transparent: I found it while reading the parser after #10109, not from a real-world file. I agree that a lone My reasoning was about the @BastienGimbert's case is stronger: an XBM file written by Pillow itself fails when fed in small chunks through If you'd rather handle this differently, I'm happy to adjust or close. |
|
I'm not entirely convinced by the Parser scenario, as I think the chunk size demonstrated is unrealistically small, and I don't know about the longevity of Parser in general - but I'll merge. |
Changes proposed in this pull request:
Image.open()on a file starting with#define FOO bar(e.g. a C header) raisesValueErrorfromint()instead ofUnidentifiedImageError, becauseValueErroris not one of the exceptionsopen()treats as "not this format".SyntaxError("not a XBM file")instead.