One function
get_bytes in h2non/filetype.py
The author described this change as “fix: restore reader position after retrieving signature bytes”. It counts as a record because the check below fails on the code as it stood at bfc4a380f and passes on bb8fe4cd3, with nothing else changed between the two runs.
Projecth2non/filetype.py
Fix saved2022-08-10
Sharing licenceMIT · LICENSE
Change size+9 −1
What the code was meant to do, written into the code itself as a docstring
Infers the input type and reads the first 8192 bytes, returning a sliced bytearray. Args: obj: path to readable, file-like object(with read() method), bytes, bytearray or memoryview Returns: First 8192 bytes of the file content as bytearray type. Raises: TypeError: if obj is not a supported type.
The change
| 4 | 4 | returning a sliced bytearray. | |
| 5 | 5 | ||
| 6 | 6 | Args: | |
| 7 | - | obj: path to readable, file-like object(with read() method), bytes, bytearray or memoryview | |
| 7 | + | obj: path to readable, file-like object(with read() method), bytes, | |
| 8 | + | bytearray or memoryview | |
| 8 | 9 | ||
| 9 | 10 | Returns: | |
| 10 | 11 | First 8192 bytes of the file content as bytearray type. | |
| ⋯ | |||
| 26 | 27 | ||
| 27 | 28 | if isinstance(obj, pathlib.PurePath): | |
| 28 | 29 | return get_signature_bytes(obj) | |
| 30 | + | ||
| 31 | + | if isinstance(obj, BufferedIOBase): | |
| 32 | + | start_pos = obj.tell() | |
| 33 | + | obj.seek(0) | |
| 34 | + | magic_bytes = obj.read(_NUM_SIGNATURE_BYTES) | |
| 35 | + | obj.seek(start_pos) # restore reader position | |
| 36 | + | return get_bytes(magic_bytes) | |
| 29 | 37 | ||
| 30 | 38 | if hasattr(obj, 'read'): | |
| 31 | 39 | return get_bytes(obj.read(_NUM_SIGNATURE_BYTES)) | |
The check that tells the two apart
fail→pass·tests/test_types.py::TestFileType::test_guess_jpeg
Check file tests/test_types.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before itbfc4a380fc8a56c15f133e92bcef69f0003828bc
Broken version dated2022-08-07
Modulefiletype.utils
Units changedget_bytes
Fingerprint05666724ec698f5a
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in h2non/filetype.py
- 2022-08-05get_bytes