fix(patcher): cap the output size a patch can declare (#5632)

* fix(patcher): cap the output size a patch can declare

RomPatcher.js allocates the patched ROM from the size written in the
patch header, so a few-byte UPS/BPS/APS/BDF/RUP patch could make the
Node patcher allocate and write gigabytes. patcher.js now wraps the
BinFile constructor and refuses any allocation above a cap passed by
the backend: twice the source ROM, or the ROM plus 64 MiB when that is
larger, never above ROM_PATCHER_MAX_FILE_SIZE_BYTES. An oversized
output is reported with exit code 3 and surfaces as a 400.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(patcher): run the output size guard through the real patcher.js

The CI pytest job now installs Node and RomPatcher.js so the patcher
tests can exercise patcher.js itself: a UPS patch declaring a 2 GiB
output is rejected, and one growing the ROM within the cap applies.
The tests skip when node or RomPatcher.js is missing locally.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Georges-Antoine Assi
2026-11-17 08:56:12 -05:00
committed by GitHub
parent 00e40bdeb1
commit 87c38eebf6
5 changed files with 189 additions and 8 deletions

View File

@@ -76,6 +76,16 @@ jobs:
sync-args: --extra test
apt-packages: 7zip
# The ROM patcher tests run the real patcher.js, which needs RomPatcher.js.
- name: Set up Node.js
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: frontend/.nvmrc
- name: Install the ROM patcher dependencies
working-directory: backend/utils/rom_patcher
run: npm ci --ignore-scripts --no-audit --no-fund
- name: Initiate MariaDB database
if: matrix.db == 'mariadb'
env: