Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(editor): reject zero-size and non-boolean window state instead of restoring it

超超超超超级喜欢你的达妮娅953e6b11ccad
diff --git a/electron/editorWindowState.test.ts b/electron/editorWindowState.test.ts
index 9490f6753..a9dbcdcad 100644
--- a/electron/editorWindowState.test.ts
+++ b/electron/editorWindowState.test.ts
@@ -77,4 +77,32 @@ describe("editor window state", () => {
);
expect(loadEditorWindowState(dir)).toBeNull();
});
+
+ it("rejects zero or negative dimensions instead of clamping them up", () => {
+ // A width:0 record is garbage the app never writes; letting it through
+ // would restore a min-size non-maximized window instead of the default.
+ for (const dims of [
+ { width: 0, height: 720 },
+ { width: 1280, height: 0 },
+ { width: -1280, height: 720 },
+ ]) {
+ const dir = tmp();
+ writeFileSync(
+ path.join(dir, "editor-window.json"),
+ JSON.stringify({ x: 10, y: 20, ...dims, maximized: false }),
+ );
+ expect(loadEditorWindowState(dir)).toBeNull();
+ }
+ });
+
+ it("rejects a non-boolean maximized rather than coercing it", () => {
+ for (const maximized of ["true", 1, null, undefined]) {
+ const dir = tmp();
+ writeFileSync(
+ path.join(dir, "editor-window.json"),
+ JSON.stringify({ x: 10, y: 20, width: 1280, height: 720, maximized }),
+ );
+ expect(loadEditorWindowState(dir)).toBeNull();
+ }
+ });
});
diff --git a/electron/editorWindowState.ts b/electron/editorWindowState.ts
index ceeb33856..6597e3736 100644
--- a/electron/editorWindowState.ts
+++ b/electron/editorWindowState.ts
@@ -37,11 +37,17 @@ function isFiniteNumber(value: unknown): value is number {
export function parseEditorWindowState(raw: unknown): EditorWindowState | null {
if (!raw || typeof raw !== "object") return null;
const rec = raw as Record<string, unknown>;
+ // Zero/negative dimensions and a non-boolean `maximized` are garbage the
+ // app never writes; restoring them would clamp into a small non-maximized
+ // window instead of the documented default. Reject the record whole.
if (
!isFiniteNumber(rec.x) ||
!isFiniteNumber(rec.y) ||
!isFiniteNumber(rec.width) ||
- !isFiniteNumber(rec.height)
+ !isFiniteNumber(rec.height) ||
+ rec.width <= 0 ||
+ rec.height <= 0 ||
+ typeof rec.maximized !== "boolean"
) {
return null;
}
@@ -50,7 +56,7 @@ export function parseEditorWindowState(raw: unknown): EditorWindowState | null {
y: rec.y,
width: rec.width,
height: rec.height,
- maximized: rec.maximized === true,
+ maximized: rec.maximized,
};
}