Repository navigation
Retire the Media Parser Fuzz Gate, Since Its Inputs Are Trusted #570
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| """Constructed media the media gate tests build their cases from.""" | ||
|
|
||
| import struct | ||
| import zlib | ||
|
|
||
|
|
||
| def jpeg_segment(marker: int, body: bytes) -> bytes: | ||
| return bytes((0xFF, marker)) + struct.pack(">H", len(body) + 2) + body | ||
|
|
||
|
|
||
| def exif_segment() -> bytes: | ||
| """An Exif APP1 carrying only Orientation.""" | ||
| entry = struct.pack("<HHIHH", 0x0112, 3, 1, 6, 0) | ||
| tiff = b"II" + struct.pack("<HI", 42, 8) + struct.pack("<H", 1) + entry | ||
| return jpeg_segment(0xE1, b"Exif\x00\x00" + tiff + struct.pack("<I", 0)) | ||
|
|
||
|
|
||
| def exif_ifd_segment( | ||
| entries: list[tuple[int, int, int, bytes]], pad: bytes = b"" | ||
| ) -> bytes: | ||
| """An Exif APP1 with one IFD holding the given tag, type, count and value entries. | ||
|
|
||
| A pad goes between the IFD and the values it points to, as a writer aligning them leaves one. | ||
| """ | ||
| table, values = b"", b"" | ||
| start = 8 + 2 + 12 * len(entries) + 4 + len(pad) | ||
| for tag, kind, count, value in entries: | ||
| if len(value) > 4: | ||
| field = struct.pack("<I", start + len(values)) | ||
| values += value | ||
| else: | ||
| field = value.ljust(4, b"\x00") | ||
| table += struct.pack("<HHI", tag, kind, count) + field | ||
| ifd = struct.pack("<H", len(entries)) + table + struct.pack("<I", 0) | ||
| tiff = b"II" + struct.pack("<HI", 42, 8) + ifd + pad + values | ||
| return jpeg_segment(0xE1, b"Exif\x00\x00" + tiff) | ||
|
|
||
|
|
||
| DATE = b"2001:01:01 00:00:00\x00" | ||
| ORIENTATION = (0x0112, 3, 1, struct.pack("<H", 6)) | ||
|
|
||
| JFIF = b"JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00" | ||
| ADOBE = b"Adobe\x00\x64\x00\x00\x00\x00\x01" | ||
|
|
||
|
|
||
| def bend(fields: bytes, at: int, value: bytes) -> bytes: | ||
| """A fixed-shape segment's fields with the bytes at one offset replaced.""" | ||
| return fields[:at] + value + fields[at + len(value) :] | ||
|
|
||
|
|
||
| SQUARE = struct.pack(">IIB", 3779, 3779, 1) | ||
| ICC = b"ICC_PROFILE\x00\x01\x01" | ||
|
|
||
|
|
||
| def jpeg_fixture() -> bytes: | ||
| """A structurally complete JPEG, with stuffed bytes and a restart marker in its scan.""" | ||
| out = b"\xff\xd8" + jpeg_segment( | ||
| 0xE0, b"JFIF\x00\x01\x01\x00\x00\x01\x00\x01\x00\x00" | ||
| ) | ||
| out += exif_segment() | ||
| out += jpeg_segment(0xDB, b"\x00" + bytes(range(64))) | ||
| out += jpeg_segment(0xC0, b"\x08\x00\x08\x00\x08\x01\x01\x11\x00") | ||
| out += jpeg_segment(0xC4, b"\x00" + bytes(16) + b"") | ||
| out += jpeg_segment(0xDA, b"\x01\x01\x00\x00\x3f\x00") | ||
| out += b"\x12\x34\xff\x00\x56\xff\xd0\x78\x9a" | ||
| return out + b"\xff\xd9" | ||
|
|
||
|
|
||
| def png_chunk(name: bytes, body: bytes) -> bytes: | ||
| crc = zlib.crc32(name + body) & 0xFFFFFFFF | ||
| return struct.pack(">I", len(body)) + name + body + struct.pack(">I", crc) | ||
|
|
||
|
|
||
| def png_fixture() -> bytes: | ||
| ihdr = struct.pack(">IIBBBBB", 1, 1, 8, 0, 0, 0, 0) | ||
| idat = zlib.compress(b"\x00\x7f") | ||
| return ( | ||
| b"\x89PNG\r\n\x1a\n" | ||
| + png_chunk(b"IHDR", ihdr) | ||
| + png_chunk(b"gAMA", struct.pack(">I", 45455)) | ||
| + png_chunk(b"IDAT", idat) | ||
| + png_chunk(b"IEND", b"") | ||
| ) | ||
|
|
||
|
|
||
| def palette_png_fixture() -> bytes: | ||
| ihdr = struct.pack(">IIBBBBB", 1, 1, 1, 3, 0, 0, 0) | ||
| idat = zlib.compress(b"\x00\x00") | ||
| return ( | ||
| b"\x89PNG\r\n\x1a\n" | ||
| + png_chunk(b"IHDR", ihdr) | ||
| + png_chunk(b"PLTE", bytes(6)) | ||
| + png_chunk(b"IDAT", idat) | ||
| + png_chunk(b"IEND", b"") | ||
| ) | ||
|
|
||
|
|
||
| def gif_fixture() -> bytes: | ||
| head = b"GIF89a" + struct.pack("<HH", 1, 1) + b"\x80\x00\x00" + bytes(6) | ||
| netscape = b"\x21\xff\x0bNETSCAPE2.0\x03\x01\x00\x00\x00" | ||
| control = b"\x21\xf9\x04\x00\x00\x00\x00\x00" | ||
| image = b"\x2c" + struct.pack("<HHHH", 0, 0, 1, 1) + b"\x00" | ||
| return head + netscape + control + image + b"\x02\x02\x44\x01\x00" + b"\x3b" | ||
|
|
||
|
|
||
| def riff_chunk(name: bytes, body: bytes) -> bytes: | ||
| return ( | ||
| name + struct.pack("<I", len(body)) + body + (b"\x00" if len(body) & 1 else b"") | ||
| ) | ||
|
|
||
|
|
||
| def webp_fixture() -> bytes: | ||
| body = riff_chunk(b"VP8X", bytes(10)) + riff_chunk(b"VP8L", b"\x2f\x00\x00\x00\x00") | ||
| return b"RIFF" + struct.pack("<I", len(body) + 4) + b"WEBP" + body | ||
|
|
||
|
|
||
| def animated_webp_fixture() -> bytes: | ||
| """An animated WebP of one frame, which holds its own chunks inside an ANMF.""" | ||
| frame = bytes(12) + b"\x64\x00\x00\x00" | ||
| frame += riff_chunk(b"VP8L", b"\x2f\x00\x00\x00\x00") | ||
| body = riff_chunk(b"VP8X", b"\x02" + bytes(9)) + riff_chunk(b"ANIM", bytes(6)) | ||
| body += riff_chunk(b"ANMF", frame) | ||
| return b"RIFF" + struct.pack("<I", len(body) + 4) + b"WEBP" + body |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.