Description
In TrimControl.tsx, the handleEnd function dispatches a state update to the global recipe object before validating the user's input. If a user enters an invalid value (resulting in NaN) or a value that is out of bounds, the application's state is corrupted with NaN for trimEnd. Because NaN > duration evaluates to false, this bypasses the pre-export validation in useVideoEditor.ts, passing the invalid state directly to FFmpeg which causes the export to fail or crash.
To Reproduce
Steps to reproduce the behavior:
- Upload a valid video file.
- In the "Trim" section, type an invalid character or partially clear the "End (sec)" input field (so that
parseFloat results in NaN).
- Note that the UI correctly displays an inline error message ("Enter a valid number.").
- Click the "Export" button.
- The export will attempt to run (bypassing validation) and subsequently crash/fail because the underlying
recipe.trimEnd state is corrupted.
Expected behavior
The recipe state should only be updated after the input has been fully validated (similar to how handleStart currently operates). If the input is invalid, the state should remain unchanged, and the export validation should correctly block the export.
Code Snippet
// src/components/TrimControl.tsx
const handleEnd = (val: string) => {
// ...
const n = parseFloat(val);
// 🐛 BUG: State is updated before validation
onChange({ trimEnd: n });
if (isNaN(n)) {
setEnd(true);
setEndErrorMsg("Enter a valid number.");
return;
}
// ...
}
Description
In
TrimControl.tsx, thehandleEndfunction dispatches a state update to the globalrecipeobject before validating the user's input. If a user enters an invalid value (resulting inNaN) or a value that is out of bounds, the application's state is corrupted withNaNfortrimEnd. BecauseNaN > durationevaluates tofalse, this bypasses the pre-export validation inuseVideoEditor.ts, passing the invalid state directly to FFmpeg which causes the export to fail or crash.To Reproduce
Steps to reproduce the behavior:
parseFloatresults inNaN).recipe.trimEndstate is corrupted.Expected behavior
The
recipestate should only be updated after the input has been fully validated (similar to howhandleStartcurrently operates). If the input is invalid, the state should remain unchanged, and the export validation should correctly block the export.Code Snippet