Skip to content

world_build: an overflowing Embedded Index / ShaderIndex is skipped, not a traceback - #5108

Open
SebSilent wants to merge 1 commit into
ItsNotRexed:mainfrom
SebSilent:fix/world-build-index-overflow
Open

SebSilent wants to merge 1 commit into
ItsNotRexed:mainfrom
SebSilent:fix/world-build-index-overflow

Conversation

@SebSilent

@SebSilent SebSilent commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: new BUILD item, world_build overflowing Embedded Index / ShaderIndex

What and why

resolve_model_textures in tools/world_build.py turns a manifest's texture indices into ints under a narrow guard:

raw_idx = emb.get("Index")
if raw_idx is None or isinstance(raw_idx, bool):
    continue
try:
    idx = int(raw_idx)
except (TypeError, ValueError):
    continue

and the same shape for Materials[].ShaderIndex (sidx = int(raw_sidx)). The intent is to skip any index it cannot read and keep building.

A JSON number like 1e400 parses to inf, and int(inf) raises OverflowError. That is neither a TypeError nor a ValueError, so the local guard misses it, and main's except (FileNotFoundError, ValueError, OSError) misses it too. One overflowing index therefore escapes as a full traceback and aborts the whole world build (exit 1), instead of being skipped like the unreadable index it is.

Reproduced on 3faac557 through the CLI: a models/manifest.json whose item has Embedded[0].Index = 1e400 (or Materials[0].ShaderIndex = 1e400) gives OverflowError: cannot convert float infinity to integer, exit 1.

The fix adds OverflowError to both guards, so a non-finite index is skipped exactly like a non-numeric string already is. Finite indices (ints, numeric strings, whole floats) are unchanged.

Tested

Linux (CachyOS), Python 3.14.10. CPU only, no game files; the manifest and OBJ are the suite's existing synthetic assets.

  • python -I tests/test_world_build.py: 60 tests OK, including the new test_overflowing_texture_index_is_skipped_not_a_traceback. For both Index and ShaderIndex it builds with the field set to 1e400 and -1e400 and asserts the output is byte-identical to building with that field set to an already-skipped "not-a-number" (and that both models still build).
  • Red before: with the tool change stashed, the test errors with OverflowError: cannot convert float infinity to integer; green after with the fix.
  • python -m compileall -q tools/world_build.py tests/test_world_build.py, git diff --check: clean.

Note: distinct from #4433 (os.walk onerror) and my #5047 (staging pack); no overlap with the open world_build PRs, none of which touch these index conversions.

AI-assisted: yes (Tacit).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • Not a new translator rule, so no contract-table change is needed.

resolve_model_textures converted the Embedded Index and the Materials
ShaderIndex with int() under a (TypeError, ValueError) guard. A JSON
float like 1e400 is infinity, and int(inf) raises OverflowError, which
that guard and main's (FileNotFoundError, ValueError, OSError) both miss,
so one bad index crashed the whole build with a traceback. Catch
OverflowError alongside the others so a non-finite index is skipped like
any other unreadable one. Finite indices are unchanged.

AI-assisted (Tacit).
@Atomic258

Copy link
Copy Markdown
Contributor

Independent check — pass (CPU only, synthetic world packs, no game files).

Environment: Windows 11, CPython 3.15.2.

  • python -I tests/test_world_build.py → 60/60 on the PR head
  • Negative control: same suite against main's tools/world_build.py → 2 errors — an overflowing EmbeddedIndex/ShaderIndex crashes the pack on the parent, skipped cleanly on the head

AI-assisted (Devin).

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this at 4c4d4ed58 on Windows 11: pytest tests/test_world_build.py -q -> 60 passed, 130 subtests passed; git diff --check clean.

An Embedded Index / ShaderIndex whose offset or count overflows the staging pack is now skipped (and counted) instead of raising a struct.error/OverflowError traceback; the added cases cover the overflowing and valid entries. No blocking issue.

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified 4c4d4ed on Windows CPU. Two cached placements gave byte-identical outputs before and after, with both original external and synthetic embedded bindings. Three textured primitives matched their expected slots and decoded DDS pixels. All eight overflow controls failed on the parent and preserved the clean build output on head. AI-assisted.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 4c4d4ed on Windows Server 2022, CPython 3.13.12: pass

  • python -I tests/test_world_build.py -> Ran 60 tests, OK
  • Negative control (tools/world_build.py swapped to upstream/main): FAILED (errors=2)

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

@kotekompotek

Copy link
Copy Markdown

Independent Windows CPU verification on 4c4d4ed5:

  • python -m pytest tests/test_world_build.py --basetemp D:\temp\pytest_tmp -q: 60 passed in 15.74s

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.

5 participants