Repository navigation
world_index: member type schema validation and strict JSON float compliance - #6318
Open
HalpDmaGetIommuInterface wants to merge 2 commits into
Open
HalpDmaGetIommuInterface wants to merge 2 commits into
HalpDmaGetIommuInterface wants to merge 2 commits into
Conversation
Contributor
|
The new schema check accepts a one-byte map name, but the reader uses four bytes for that field. Three bytes after the field can therefore change the reported map name. I reproduced this on 76b8990 with the synthetic fixture. Run this script from the repository root with import runpy
t = runpy.run_path("tests/test_world_index.py")
b = bytearray(t["make_resource"]())
b[0x3A8] = 0x11 # unsigned byte, accepted by MAPDATA_MEMBER_TYPES for name
b[0x508:0x50C] = bytes.fromhex("12 34 56 78")
print(hex(t["WI"].parse_resource(b)["map_name"]))Actual result: 0x78563412. For the accepted one-byte declaration, the value is 0x12. If map names require four bytes, reject this declaration. Otherwise, read the value at its declared width. The same read occurs on base 3faac55. The new validation still permits it. The world_index suite passed 39 tests and skipped one on Windows. The three added tests failed on the base. AI-assisted. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes two issues in
tools/world_index.py:Schema Member Type Validation (world_index: a mismatched member type crashes the scan with TypeError #5601):
CEntityDefandCMapDataschemas,parse_resource()previously read named members by hash without validating that their type byte matched the expected field type.positionwas declared as a scalar float (0x21) rather than vector3 (0x32/0x33),positions.append(pos)appended a float, subsequently causingmin(p[i] for p in positions)to raiseTypeError: 'float' object is not subscriptableescapingmain()as a traceback.archetypeNameorlodLevelas vector types raisedTypeErrorin set/dict lookups.offset + width <= struct_size) are validated againstENTITY_MEMBER_TYPESandMAPDATA_MEMBER_TYPESbefore block processing, returningNoneif the schema is malformed as documented in the docstring. Defensive type guards are also added to entity collection.Strict JSON Non-Finite Float Compliance (world_index: non-finite placement floats are written as NaN/Infinity, which is not JSON #5602):
NaN,Infinity,-Infinity) previously passed through_r4and were written directly to--outJSON via Python's defaultjson.dump, producing non-standard JSON that causes syntax errors in strict parsers.lodDist >= 0permitted+infintolod_dists.math.isfinite():position_min/position_maxdrop non-finite components during aggregation and emitnullfor components lacking finite values._r4()emitnullfor non-finite components orNoneif entirely non-finite.lod_dist_min/lod_dist_maxignore+infandNaN.allow_nan=Falseis enforced acrossjson.dump/json.dumpscalls matching other repo tools (world_build.py,rbf0_tree.py,glb_inspect.py, etc.).Verification
tests/test_world_index.py:test_schema_member_type_mismatch_is_rejected: verifies malformed member types (0x21position,0x32archetype/lodLevel/extent, out-of-bounds offset) reject cleanly.test_non_finite_placement_floats_produce_valid_json: verifies non-finite coordinates produce valid strict JSON (null), verified with strict JSON parser.test_non_finite_lod_dist_is_ignored: verifies+inf/NaNlod distances are ignored.tests/test_world_index.py(40 passed).tests/test_world_archetypes.py: PASStests/test_world_build.py: PASStests/test_world_build_output_lock.py: PASStests/test_world_census.py: PASStests/test_world_index.py: PASStests/test_world_index_three_streams.py: PASStests/test_world_instancing.py: PASStests/test_world_interior_names.py: PASStests/test_world_json_atomic.py: PASStests/test_world_lights_paths.py: PASStests/test_world_names.py: PASStests/test_world_place.py: PASStests/test_world_placement_identity.py: PASSCloses #5601
Closes #5602
Coordinated on #6089 (#6089 (comment))
AI-assisted: yes.