Skip to content

fix: improve data.pack scan reliability and path handling#12

Open
ibraved wants to merge 1 commit intoakioukun:mainfrom
ibraved:fix-datapack-scan-missing-entries
Open

fix: improve data.pack scan reliability and path handling#12
ibraved wants to merge 1 commit intoakioukun:mainfrom
ibraved:fix-datapack-scan-missing-entries

Conversation

@ibraved
Copy link

@ibraved ibraved commented Feb 28, 2026

Problem

Scan Tree was missing many files from data.pack.

The likely causes were in scanning/parsing robustness:

  1. Header fields were read using direct pointer casts for 32-bit integers, which is brittle.
  2. False-positive header matches could be accepted, causing cursor jumps by container_len and skipping valid entries.
  3. Path handling accepted malformed path strings and relied on std::filesystem::path for in-pack virtual paths, which can behave unexpectedly for non-filesystem path data.

What This PR Changes

File changed: DataPack.cpp

  1. Added safe LE integer reads with read_u32_le(...) instead of direct pointer casts.
  2. Added sanitize_pack_path(...):
    • trims trailing NUL
    • normalizes \ to /
    • strips leading/trailing /
  3. Added path plausibility filtering with is_likely_pack_path(...) before accepting entries.
  4. Kept path_len validation aligned to byte max (<= 255).
  5. Reworked AddFileToTree(...) to avoid std::filesystem::path for virtual in-pack paths:
    • manual path splitting
    • stable folder creation
    • extension detection from filename

Why This Fixes It

  • Reduces false header acceptance and prevents invalid large cursor jumps that skip real files.
  • Normalizes and validates path values before tree insertion.
  • Handles in-pack paths as virtual paths rather than OS filesystem paths, avoiding accidental path interpretation side effects.

Validation

  • Configured and built project successfully in Release.
  • Executable starts successfully in smoke test.
  • Manual UI verification should be done with the same data.pack repro case to confirm all expected files appear in Scan Tree.

Scope

  • Focused only on scanner/path/tree logic in DataPack.cpp.
  • No unrelated behavioral changes intended.

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.

1 participant