Skip to content

restofworld_index: read a carve index.json saved with a UTF-8 BOM - #6042

Open
evilclanker9000 wants to merge 2 commits into
ItsNotRexed:mainfrom
evilclanker9000:deepseek/5-restofworld-index-bom
Open

evilclanker9000 wants to merge 2 commits into
ItsNotRexed:mainfrom
evilclanker9000:deepseek/5-restofworld-index-bom

Conversation

@evilclanker9000

Copy link
Copy Markdown
Contributor

tools/restofworld_index.py::_carve_index opened a carve folder's index.json as strict utf-8. One saved with a
UTF-8 BOM — PowerShell 5.1's Set-Content/Out-File default, which is how the carve folder is usually produced on
Windows — made json.load raise, the surrounding except (OSError, ValueError, ...) swallowed it as {}, and folder
mode silently fell back to the length on disk. stored / compressed_bytes / readable_fraction were then the
inflated sizes with no error, so the summary told the opposite of what the archive mode means. Read it as
utf-8-sig, the same fix world_index._carve_successors (#6017) and classify_carve (#5960) took.

Test

python -I tests\test_restofworld_index.py

Before the fix (new test only), FolderModeStoredBytesTest:

FAIL: test_index_json_saved_with_a_bom_supplies_stored_bytes
AssertionError: 1000 != 300
Ran 3 tests in 0.021s
FAILED (failures=1)

After the fix, the whole file:

Ran 34 tests in 1.513s

OK

No GPU needed.

Notes

EGEN-RESTOFWORLD-INDEX-BOM (DeepSeek5)

AI-assisted.

_carve_index opened index.json as strict UTF-8, so a BOM (PowerShell 5.1's Set-Content/Out-File default) made json.load raise, the except swallowed it as {}, and the inflated length on disk was reported as the stored size.
… sizes

Without the utf-8-sig read the folder mode reports 1000 (the inflated length on disk) instead of the 300 stored bytes the index names.
@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

The UTF-8 BOM fix works at 714f5824. The new test docstring and the PR description give the wrong default for Windows PowerShell 5.1. This matters because the default Out-File command still produces the wrong stored-byte count.

I used Windows PowerShell 5.1.26100.9818 with the synthetic fixture from FolderModeStoredBytesTest.make. Its payload is 1,000 bytes on disk. The index gives a stored size of 300. I wrote the same ASCII JSON to a new index.json with each command and ran restofworld_index.scan_dir:

PowerShell command First bytes Reported stored bytes
$json | Set-Content index.json 7b 22 73 75 300
$json | Out-File index.json ff fe 7b 00 1,000
$json | Set-Content -Encoding UTF8 index.json ef bb bf 7b 300

Please name Set-Content -Encoding UTF8 as the example in the test and description. Default Out-File writes UTF-16LE. The reader silently falls back to the inflated length for that file.

All 34 tests pass with py -3.14 -I tests/test_restofworld_index.py on Windows 11. Against the merge base 561b65a8, the new UTF-8 BOM test reports 1,000 instead of 300. The other two stored-size tests pass.

AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants