-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Fix DDS Timeout issues in oss-fuzz #9404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
63ff7ca
f15886a
020f890
cd1c9f1
326bfde
65a9bbc
6a421d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -503,21 +503,34 @@ def decode(self, buffer: bytes | Image.SupportsArrayInterface) -> tuple[int, int | |||||||||||
| while mask >> (offset + 1) << (offset + 1) == mask: | ||||||||||||
| offset += 1 | ||||||||||||
| mask_offsets.append(offset) | ||||||||||||
| mask_totals.append(mask >> offset) | ||||||||||||
| mask_total = mask >> offset | ||||||||||||
| if not mask_total: | ||||||||||||
| mask_totals.append(0) | ||||||||||||
| else: | ||||||||||||
| mask_totals.append(255 / mask_total) | ||||||||||||
|
|
||||||||||||
| data = bytearray() | ||||||||||||
| bytecount = bitcount // 8 | ||||||||||||
| dest_length = self.state.xsize * self.state.ysize * len(masks) | ||||||||||||
| while len(data) < dest_length: | ||||||||||||
| value = int.from_bytes(self.fd.read(bytecount), "little") | ||||||||||||
| # consume the data | ||||||||||||
| has_more = True | ||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bytecount is number of bytes per pixel, or the number of masks. It's not the data size.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but if
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But bytecount should never be zero. It’s an image level compression property, how many bytes do we consume per pixel. To me, this looks like a misunderstanding, so can you explain why it’s better to initialize with this rather than the simpler expression for true?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
...awkwardly, it does seem to be possible. I mean, it doesn't seem helpful value, and I do think it should lead to an error. Pillow/src/PIL/DdsImagePlugin.py Lines 355 to 356 in bc64ccb
Pillow/src/PIL/DdsImagePlugin.py Line 509 in bc64ccb
Here's the documentation - https://learn.microsoft.com/en-us/windows/win32/direct3ddds/dds-pixelformat
To demonstrate, I've added radarhere@c90d124 onto a fork of this branch - https://github.com/radarhere/Pillow/actions/runs/21312659863/job/61351156707#step:11:58
|
||||||||||||
| while len(data) < dest_length and has_more: | ||||||||||||
| chunk = self.fd.read(bytecount) | ||||||||||||
| # work around BufferedIO not being seekable | ||||||||||||
| has_more = len(chunk) > 0 | ||||||||||||
| value = int.from_bytes(chunk, "little") | ||||||||||||
| for i, mask in enumerate(masks): | ||||||||||||
| masked_value = value & mask | ||||||||||||
| # Remove the zero padding, and scale it to 8 bits | ||||||||||||
| data += o8( | ||||||||||||
| int(((masked_value >> mask_offsets[i]) / mask_totals[i]) * 255) | ||||||||||||
| if mask_totals[i] | ||||||||||||
| else 0 | ||||||||||||
| ) | ||||||||||||
| data += o8(int((masked_value >> mask_offsets[i]) * mask_totals[i])) | ||||||||||||
|
|
||||||||||||
| # extra padding pixels -- always all 0 | ||||||||||||
| if len(data) < dest_length: | ||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the file stopped before we were able to read all the bytes we needed, why not just let the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question - I couldn't tell if it was intentional that it filled off the end. Given that it's plain black, it's at least a reasonable fill, but I didn't see a spec. I'd be happy enough erroring out as well. Main issue here is that I want to catch things other than dds timeouts in oss-fuzz.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've created #9405 |
||||||||||||
| pixel = bytearray() | ||||||||||||
| pixel += o8(0) | ||||||||||||
| ct_bytes = dest_length - len(data) | ||||||||||||
| data += pixel * ct_bytes | ||||||||||||
|
|
||||||||||||
| self.set_as_raw(data) | ||||||||||||
| return -1, 0 | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.