Skip to content

fix: reject non-finite and out-of-range geometry in gin converters - #54216

Merged
MarshallOfSound merged 1 commit into
electron:mainfrom
xia-chao:fix/setbounds-overflow-crash
Sep 25, 2026
Merged

MarshallOfSound merged 1 commit into
electron:mainfrom
xia-chao:fix/setbounds-overflow-crash

Conversation

@xia-chao

Copy link
Copy Markdown
Contributor

Description of Change

Non-finite and out-of-range values passed to geometry APIs (setBounds and friends) were silently
accepted instead of rejected. Rect, Point, and Insets in gfx_converter.cc now validate like
Size already did in the same file. Fractional bounds such as x: 440.5 still work.

Adds one spec covering NaN, ±Infinity, and -1e10.

Built and tested

Built from this branch on a self-hosted 64-core / 128 GB machine. No Electron CI was used.

$ ninja -C out/Debug electron -j 64
41031 targets, 0 failed  ->  out/Debug/electron (4.8 GB)
$ out/Debug/electron --no-sandbox --version
v46.0.0-nightly.20260918

$ node script/spec-runner.js --runners=main --skipYarnInstall --no-sandbox \
    -g "throws on non-finite or out-of-range bounds"
# pass 1 | # fail 0 | Electron main process tests passed.
Full evidence — crash log, build output, spec output, debugger session, screenshots

Crash on the published binary (no build needed)

const { app, BaseWindow } = require('electron');
app.whenReady().then(() => {
  const w = new BaseWindow({ width: 400, height: 300 });
  w.setBounds({ x: -1e10, y: -1e10, width: 400, height: 300 });
});
BEFORE: {"x":520,"y":300,"width":400,"height":300}
TRIGGER: -10000000000  REPEAT: 40
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason:
'Invalid parameter not satisfying: CGRectContainsRect(CGRectMake(
  (CGFloat)INT_MIN, (CGFloat)INT_MIN,
  (CGFloat)INT_MAX - (CGFloat)INT_MIN, (CGFloat)INT_MAX - (CGFloat)INT_MIN), frame).
  self=<ElectronNSWindow: 0x1040007a780> frame={{-2147483648, 2147484548}, {0, 0}}'

Exit code 133 (128 + SIGTRAP(5)). Note frame={{-2147483648, ...}} — x is exactly INT_MIN,
confirming the float-to-int saturation path rather than a rounding artifact. try/catch cannot
intercept this. NaN does not crash but is silently coerced to 0.

Build output

$ cd src && ninja -C out/Debug electron -j 64

Total targets : 41031
Failed        : 0

[41029/41031] CXX obj/ui/webui/tracked_element/tracked_element/tracked_element_handler.o ...
[41030/41031] LINK ./electron

-rwxr-xr-x 1 root root 5129168112 out/Debug/electron

$ out/Debug/electron --no-sandbox --version
v46.0.0-nightly.20260918

Spec output — repository's own runner, unmodified spec files

$ node script/spec-runner.js --runners=main --skipYarnInstall \
    --no-sandbox -g "throws on non-finite or out-of-range bounds"

ok 1 BaseWindow module sizing BaseWindow.setBounds(bounds[, animate]) throws on non-finite or out-of-range bounds
# tests 1
# pass 1
# fail 0
1..1
✓ Electron main process tests passed.

--no-sandbox is required because Chromium refuses to start as root; it is a runner argument and
no test or product code was modified for it.

Individual input checks (built binary, direct call)

PASS: {x:NaN}              -> Error processing argument at index 0, conversion failure from ...
PASS: {x:+Infinity}        -> conversion failure from ...
PASS: {x:-Infinity}        -> conversion failure from ...
PASS: {x:-1e10, y:-1e10}   -> conversion failure from ...
PASS: fractional bounds still work -> {"x":441,"y":225,"width":500,"height":401}

Screenshots

Build server and build result (64 cores, 41031 targets, 0 failed):

build server

Official spec passing:

spec passed

Debugger — source breakpoint at gfx_converter.cc:110, value already NaN on entry to ToRoundedRect:

vscode variables

Call stack through gin::Converter<gfx::Rect>::FromV8 → BaseWindow::setBounds:

vscode call stack

Debug console — BEFORE bounds printed, then TRIGGER:

debug console

Checklist

Release Notes

Notes: Window geometry APIs now reject non-finite and out-of-range values.

@xia-chao
xia-chao force-pushed the fix/setbounds-overflow-crash branch from cd26fc5 to 4c523ad Compare September 22, 2026 21:47
@MarshallOfSound MarshallOfSound added semver/patch backwards-compatible bug fixes target/45-x-y PR should also be added to the "45-x-y" branch. labels Sep 24, 2026
@MarshallOfSound

Copy link
Copy Markdown
Member

in conflict

@xia-chao
xia-chao force-pushed the fix/setbounds-overflow-crash branch from 4c523ad to fd259de Compare September 24, 2026 18:07
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ This PR contains unsigned commits. This repository enforces commit signatures
for all incoming PRs. To get your PR merged, please sign those commits
(git rebase --exec 'git commit -S --amend --no-edit -n' @{upstream}) and force push them to this branch
(git push --force-with-lease)

For more information on signing commits, see GitHub's documentation on Telling Git about your signing key.

@github-actions github-actions Bot added the needs-signed-commits Currently some or all of the commits in this PR are not signed label Sep 24, 2026
Non-finite values (NaN, Infinity) were silently coerced to 0. Huge values
like -1e10 saturated to INT_MIN and can crash AppKit on setBounds.

Assisted-By: MiMo, MiMo Desktop
@xia-chao
xia-chao force-pushed the fix/setbounds-overflow-crash branch from fd259de to a1e440b Compare September 24, 2026 18:11
@github-actions github-actions Bot removed the needs-signed-commits Currently some or all of the commits in this PR are not signed label Sep 24, 2026
@MarshallOfSound
MarshallOfSound merged commit cde6f39 into electron:main Sep 25, 2026
72 checks passed
@release-clerk

release-clerk Bot commented Sep 25, 2026

Copy link
Copy Markdown

Release Notes Persisted

Window geometry APIs now reject non-finite and out-of-range values.

@trop

trop Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

I was unable to backport this PR to "45-x-y" cleanly;
you will need to perform this backport manually.

@trop trop Bot removed the target/45-x-y PR should also be added to the "45-x-y" branch. label Sep 25, 2026
MarshallOfSound added a commit that referenced this pull request Sep 25, 2026
…s() (#54357)

#54333 made setBounds() read the partial bounds itself instead of going
through the gfx::Rect converter, so the range check #54216 added to the
converter no longer covers it and its spec fails on main.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

46-x-y no-backport semver/patch backwards-compatible bug fixes

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants