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.

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

44 returning a sliced bytearray.
55
66 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
89
910 Returns:
1011 First 8192 bytes of the file content as bytearray type.
2627
2728 if isinstance(obj, pathlib.PurePath):
2829 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)
2937
3038 if hasattr(obj, 'read'):
3139 return get_bytes(obj.read(_NUM_SIGNATURE_BYTES))

The check that tells the two apart

failpass·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