Skip to content

fix: crash/robustness — malformed project/library JSON, S-param path containment, touchstone OOM caps - #58

Merged
striderZA merged 1 commit into
masterfrom
fix/crash-and-containment
Aug 10, 2026
Merged

fix: crash/robustness — malformed project/library JSON, S-param path containment, touchstone OOM caps#58
striderZA merged 1 commit into
masterfrom
fix/crash-and-containment

Conversation

@striderZA

Copy link
Copy Markdown
Owner

Summary

Crash/robustness fixes from a comprehensive codebase review (findings C1, B7, S1, S2).

  • Malformed project JSON crashes the app (C1). ProjectSerializer::load() caught only JSON parse errors; wrong-shape-but-valid JSON ({}, "components": 5, wrong-typed params, non-object window_state) threw uncaught nlohmann exceptions and std::terminated. Now: 64 MiB size cap before parse, root must be an object, the whole load body is guarded (json::exception → log + graceful failure), and each component deserialize is isolated so one bad component is skipped while the rest load. Same crash class fixed at the library boundary (component_library loadFile catches type_error; scan tolerates filesystem_error).
  • Coax preset OOB (B7). deserialize clamped preset_index/length_m/connectors_loss_dB — previously an out-of-range index into kCoaxCablePresets from a corrupted project was UB.
  • S-param path containment (S1). S-param paths in project files now resolve against the project file's directory and must stay inside it (weakly_canonical + prefix, mirroring the extension manifest parser). Absolute/escaping paths are neutralized with a warning. Library data_files entries get the same containment. Save re-relativizes in-project absolute paths so projects stay portable.
  • Touchstone OOM caps (S2). Parser rejects > 256 MiB files before reading and enforces the 10M-point cap during the read loop instead of after buffering (~960 MB OOM window removed).

Verification

  • tests.exe: 218 test cases / 65534 assertions, all pass (216 baseline + 2 new wrong-shape JSON cases).
  • New standalone test_path_containment exe: 5 cases / 29 assertions.
  • Full build green (MinGW-w64, Debug, ninja).

Notes for merging

  • Contains a behavior change: absolute S-param paths outside the project dir are neutralized at load — keep .s2p data inside the project directory. Relative paths now resolve against the project dir (portable) instead of the process CWD.
  • Expected conflict with refactor/engine-unification in tests/test_project_file.cpp (the Fix S-param mode not reloading on project deserialize #56 test's attenuator/combiner lines: this branch stages the fixture with the old API names, that branch renames the API). Merge this branch first; resolve by keeping setSParamFilepath(local_s2p) / sparamMode().

…containment, touchstone OOM caps

C1: ProjectSerializer::load() caught only JSON *parse* errors; wrong-shape but valid JSON ({}, "components": 5, wrong-typed params, non-object window_state) threw uncaught nlohmann exceptions and std::terminated. Now: 64 MiB size cap before parse, root must be an object, whole load body wrapped (json::exception -> LOG_ERROR + graceful failure), each component deserialize isolated so one bad component is skipped and the rest load. Same crash class fixed at the library boundary (component_library loadFile catches type_error; scan tolerates filesystem_error).
B7: coax deserialize clamped preset_index/length_m/connectors_loss_dB (previously OOB index into kCoaxCablePresets from a corrupted project -> UB).
S1: S-param paths in project files resolve against the project dir and must stay inside it (weakly_canonical + prefix, mirroring the extension manifest parser); escaping/absolute-outside paths are neutralized with a warning. Library data_files entries get the same containment. Save re-relativizes in-project absolute paths for portability.
S2: touchstone parser now rejects > 256 MiB files before reading and enforces the 10M-point cap during the read loop, not after buffering (~960 MB OOM window removed).
Tests: wrong-shape JSON cases, coax clamp, new test_path_containment standalone exe (5 cases), #56 fixture staged in-project.
@striderZA
striderZA merged commit 3f59e46 into master Aug 10, 2026
2 checks passed
@striderZA
striderZA deleted the fix/crash-and-containment branch August 10, 2026 08:28
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