One function

EndOfCentralDirectoryRecord in erev0s/apkInspector

The author described this change as update eocd parse bug at offset. It counts as a record because the check below fails on the code as it stood at 4d26bfa47 and passes on 7a203a892, with nothing else changed between the two runs.

Fix saved2024-06-05
Sharing licenceApache-2.0 · LICENSE
Change size+6 6

What the code was meant to do, written into the code itself as a docstring

A class to provide details about the end of central directory record.

The change

3434 signature_offset = -1
3535 file_size = apk_file.seek(0, 2)
3636 while offset < file_size:
37- position = file_size - offset - chunk_size
38- if position < 0:
39- position = 0
37+ position = max(0, file_size - offset - chunk_size)
4038 apk_file.seek(position)
4139 chunk = apk_file.read(chunk_size)
4240 if not chunk:
4341 break
44- signature_offset = chunk.rfind(b'\x50\x4b\x05\x06') # end of Central Directory File Header signature
42+ signature_offset = chunk.rfind(b'\x50\x4b\x05\x06') # EOCD signature
4543 if signature_offset != -1:
4644 eo_central_directory_offset = position + signature_offset
47- break # Found End of central directory record (EOCD) signature
48- offset += chunk_size
45+ break # Found EOCD signature
46+ # Adjust offset to overlap by 4 bytes
47+ offset += chunk_size - 4
48+
4949 if signature_offset == -1:
5050 raise ValueError("End of central directory record (EOCD) signature not found")
5151 apk_file.seek(eo_central_directory_offset)

The check that tells the two apart

failpass·tests/test_base.py::ApkInspectorTestCase::test_find_eocd_at_offset_1026

Check file tests/test_base.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 it4d26bfa473897446e32518d2a1faeb628aedc0af
Broken version dated2024-05-05
ModuleapkInspector.headers
Units changedEndOfCentralDirectoryRecord
Fingerprint5697e69585b0f70f
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.