Skip to content

Bound untrusted render input with clamps and a shared pixel budget - #116

Open
Aerhhh wants to merge 1 commit into
masterfrom
security/input-clamps-pixel-budget
Open

Aerhhh wants to merge 1 commit into
masterfrom
security/input-clamps-pixel-budget

Conversation

@Aerhhh

@Aerhhh Aerhhh commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Why

A security review found that several short, untrusted inputs could make a single render allocate gigabytes and take down the host JVM. Four were reproduced against master with a 1 GB heap:

Input Result on master
lore %%dot:5000000%% OutOfMemoryError
tooltip padding=8000 OutOfMemoryError
inventory 120 x 120 OutOfMemoryError, thrown raw on the caller's thread
scene {"schema_version":1e400000000,...} 6.7 s and a 400 MB error string from 40 bytes

What changed

  • RenderLimits (new): a canvas and animation pixel budget checked before every canvas allocation: tooltip, inventory, container, HUD, scene compositor, glint effect and the GeneratorImageBuilder composites. Over budget fails with GeneratorValidationException. Both limits are system properties (generator.render.maxCanvasPixels, default 25M; generator.render.maxAnimationPixels, default 400M).
  • Icon placeholders: repeat counts clamp to 100. A negative count now yields an empty string instead of an uncaught IllegalArgumentException.
  • Tooltip padding: clamps to 255, the range its javadoc already documented.
  • Inventories: at most 64 rows and 64 slots per row, in both InventoryRequest and the generator builder; the canvas is also budget-checked.
  • StrictJson: number literals over 64 characters or with an exponent over 400 are rejected at read time, so error messages no longer expand them.
  • Scenes: scale at most 16; margin, spacing, columns, gui_width and at/offset values at most 4096.
  • Content templates: one fill produces at most 1,000,000 characters and nodes of output.
  • README: new "Render limits" section.

Behaviour changes to be aware of

  • The animation default (400M pixels) leaves room for the largest stock render, a full chest with the 182-frame glint (about 256M). Anything larger now fails instead of rendering.
  • Icon counts above 100 and padding above 255 are clamped silently rather than rejected.
  • The specific numbers are my choices; adjust any that are too tight for real usage.

Testing

  • New RenderLimitsTest (11 tests) covers each case above.
  • Full generator suite: 1579 run, 1578 pass. The one error, DisplayToolTest.enchantedRenderIsAnimated, hit the library's 20 s render timeout on a loaded machine. It passes on this branch when run alone and fails the same way on unmodified master under the same load.
  • The tooling module is untouched and was not run.

Not in this PR

The review's other findings (timeout not cancelling work, resource-pack size values that bypass PackLimits, plain-HTTP skin fetch, dependency and CI hardening) are separate follow-ups.

Short request inputs could make one render allocate gigabytes: an icon
placeholder repeat count, tooltip padding, inventory rows and columns,
scene scale and offsets, a huge-exponent JSON number, and content
template fills all lacked an upper bound.

- Add RenderLimits, a canvas and animation pixel budget checked before
  every canvas allocation (tooltip, inventory, container, HUD, scene,
  glint, composite). Limits are system properties.
- Clamp icon repeat counts to 100 and tooltip padding to 255.
- Cap inventories at 64 rows and 64 slots per row.
- Reject JSON number literals over 64 characters or with an exponent
  over 400, so error messages no longer expand them.
- Cap scene scale, margin, spacing, columns, gui_width and offsets.
- Cap the output of one content template fill.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant