mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-10 20:33:48 +00:00
parse_curve computed 12 + n * 2 with n straight from the file and only checked the 1 << 20 bound afterwards, inside the table arm — on a 32-bit (wasm32) target, which craft-cms ships branches for, a trC curve count of 0xFFFFFFFF overflows with overflow checks on and panics before the guard could reject it. The mluc reader computed 16 + k * size unchecked, where wrapping reads another record's bytes as the language, length and offset (wrong text, no error) instead of stopping. Hoist the curve-count guard above the arithmetic and compute the record offset with checked_mul/checked_add, breaking out when it does not fit. This ports the app-side fix accepted as PhotoCraft #4976 / PR #5227, which was never carried into craft-cms. On a 64-bit host both sites are benign (the arithmetic fits), so the two new tests pass before and after there; they bite on a 32-bit/overflow-check build, which deserves a wasm32 CI job — craft-cms has none yet.