Исправить проверку целостности PNG

This commit is contained in:
2026-11-19 13:27:19 +03:00
parent 0b399073d6
commit 37ebf830ba
8 changed files with 229 additions and 0 deletions
+10
View File
@@ -135,6 +135,16 @@ class AttachmentsTest(unittest.TestCase):
original = self.c.call('GET', '/api/v1/attachments/' + a['id'] + '/content', actor=self.a)
self.assertEqual(original['bytes'], source)
def test_png_requires_complete_iend_and_valid_crc(self):
png = small_png()
for missing in range(1, 13):
with self.subTest(missing_final_bytes=missing):
self.upload(raw=png[:-missing], status=415)
with self.subTest(corrupt_iend_crc=True):
self.upload(raw=png[:-1] + bytes([png[-1] ^ 1]), status=415)
# A rejected upload must not prevent subsequent valid processing.
self.ready(self.upload(raw=png)['json'])
def test_corrupt_and_wrong_mime(self):
for raw, mime in ((b'not an image', 'image/png'), (self.png[:40], 'image/png'),
(self.png, 'image/jpeg'), (self.png, 'text/plain'), (b'', 'image/png')):