mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-08 10:46:06 +00:00
fix(engine): guard the rounded frame rate and strict-parse rationals
Two paths the previous guards still let through.
Rounding could recreate Infinity after the finite check. `raw * 100`
overflows for a finite-but-huge rate — "1e307", "1e307/1" — so `rounded`
became Infinity and passed the positivity check, reaching exactly the
`-r Infinity` failure the finite guard exists to prevent. The rounded
result is now checked too.
The rational operands still used parseFloat. The plain-number path
switched to Number() so trailing garbage fails the whole string, but the
numerator and denominator did not, so "60fps/1", "60/1fps" and
"30garbage/1garbage" returned valid rates while the contract says
malformed frame rates fail closed. Both operands are now parsed strictly,
and an empty operand ("/", "/1", "30/") is rejected rather than coerced.
Tests: 8 malformed inputs and 3 overflow cases in the direct table.
Reverting either fix fails 5.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
19dc83bc2b
commit
4d563fa752
@@ -618,8 +618,18 @@ describe("parseFrameRate", () => {
|
||||
expect(parseFrameRate(input)).toBe(0);
|
||||
});
|
||||
|
||||
// Fell through to a bare parseFloat that stops at trailing garbage.
|
||||
it.each(["30/1/2", "60fps"])("returns 0 for malformed input %s", (input) => {
|
||||
// Fell through to a bare parseFloat that stops at trailing garbage. The
|
||||
// rational operands had the same defect after the plain path was fixed.
|
||||
it.each(["30/1/2", "60fps", "60fps/1", "60/1fps", "30garbage/1garbage", "/", "/1", "30/"])(
|
||||
"returns 0 for malformed input %s",
|
||||
(input) => {
|
||||
expect(parseFrameRate(input)).toBe(0);
|
||||
},
|
||||
);
|
||||
|
||||
// raw * 100 overflows for a finite-but-huge rate, so the rounded value was
|
||||
// Infinity even though the pre-round guard passed.
|
||||
it.each(["1e307", "1e307/1", "1e308/0.5"])("returns 0 when rounding overflows: %s", (input) => {
|
||||
expect(parseFrameRate(input)).toBe(0);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user