Cap PixelBuffer.from_bytes dimensions at 64k x 64k

Following review feedback, the reader now rejects a header claiming a
width or height beyond 65536, guarding against malformed byte streams
that would otherwise trigger an unreasonable allocation. The writer
stays full 32-bit ('unlimited'), and native little-endian order and the
transparency mask are kept as-is. Adds Ruby and Python tests for the
oversized-header rejection.

Ref: https://github.com/KLayout/klayout/pull/2387#issuecomment-4984941409
This commit is contained in:
Kirill Osipov
2026-07-16 19:03:34 +02:00
parent 2fa7b24345
commit 9a606ec4e9
3 changed files with 21 additions and 1 deletions
+4
View File
@@ -78,6 +78,10 @@ class LAYPixelBufferTests(unittest.TestCase):
with self.assertRaises(Exception):
pya.PixelBuffer.from_bytes(data[:-4])
# a header beyond the 64k x 64k limit is rejected
with self.assertRaises(Exception):
pya.PixelBuffer.from_bytes(struct.pack("=II", 65537, 1))
# run unit tests
if __name__ == '__main__':