Skip to content

Bound size values inside resource packs - #120

Merged
Aerhhh merged 1 commit into
masterfrom
security/pack-size-limits
Nov 21, 2026
Merged

Aerhhh merged 1 commit into
masterfrom
security/pack-size-limits

Conversation

@Aerhhh

@Aerhhh Aerhhh commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Why

Follow-up to the security review (see #116). PackLimits capped entry count, entry bytes and texture side length, but several values inside a pack act as sizes and were not covered. A small pack could ask for gigabytes when one of its sprites, fonts or items was rendered, or when it was registered. This matters most for packs the host did not author.

Path handling was reviewed and found sound (zip slip, .., symlink escape, reference validation); this PR does not change it beyond two small tightenings listed at the end.

What changed

Area Before Now
GUI sprite tile / nine_slice size up to 65536 per side; a 1x1 texture could force a 4 GiB normalized copy normalized copy capped at 4M pixels
Bitmap font height unbounded 1 to 2048; ascent at least -2048; one scaled glyph capped at 16M pixels
TTF size / oversample unbounded size at most 256, oversample 1 to 16, product at most 512; glyph cell capped at 4M pixels
TTF files one temp file and native font per font id one parsed font per file per pack, at most 64 files per pack
Animation frames every grid cell, or every listed frame at most the 1200 that can ever play
Composite item models unbounded at most 64 models per item
Model elements 4096 cap applied only at render also applied at parse
Registration per-entry cap only new PackLimits.maxIndexBytes (default 256 MiB) bounds item and model JSON read while indexing
Texture format any format ImageIO recognised from content PNG only
Texture area 8192x8192 allowed under the sheet cap (256 MiB decoded) at most 16,777,216 pixels

Also:

  • The "pack is not registered" error no longer lists every registered pack id.
  • Pack-open errors carry the file name, not the full filesystem path; the full path is logged.
  • A namespace made only of dots is rejected.
  • DirectoryPackSource.exists applies the same real-path containment check as read.

Compatibility

  • PackLimits gains a sixth record component, maxIndexBytes. The existing four- and five-argument constructors still work and use the default; fromSystemProperties reads generator.pack.maxIndexBytes. Code that deconstructs the record by pattern would need updating.
  • Packs that exceed the new bounds now fail to load that font, sprite or item (or fail to register, for the index budget). The numbers are my choices, set well above what vanilla and the fixture packs use; say if a real pack needs more.

Not in this PR

  • A total budget across all texture bytes read over a pack's lifetime. Textures are read lazily and are bounded per entry and by the texture cache.
  • Wrapping every stray RuntimeException from pack JSON into PackResolveException.

Testing

  • New PackSizeLimitsTest (11 tests), one per row above plus the namespace, limits-default and error-message changes.
  • All 882 tests under pack/**, tools/pack/** and the pack-facing generator tests pass. The full suite was not run locally.

PackLimits capped entry counts, entry bytes and texture sides, but several
values inside a pack act as sizes and were not covered, so a small pack
could ask for gigabytes when rendered or registered.

- GUI sprite scaling: cap the normalized copy at 4M pixels.
- Bitmap fonts: height at most 2048, ascent at least -2048, and a 16M
  pixel cap on one scaled glyph.
- TTF fonts: size at most 256, oversample 1 to 16, product at most 512,
  a 4M pixel cap per glyph cell, one parsed font per file per pack and at
  most 64 TTF files per pack.
- Animations: stop at the 1200 frames that can ever play.
- Item models: at most 64 models per composite item; enforce the
  4096-element cap when a model is parsed.
- Registration: PackLimits.maxIndexBytes (default 256 MiB) bounds the
  item and model JSON read while indexing.
- Textures: PNG only, and at most 16M pixels whatever the per-side cap.
- Stop listing registered packs in the unknown-pack error, keep full
  filesystem paths out of pack-open errors, reject a dot-only namespace,
  and apply the real-path check in DirectoryPackSource.exists.
@Aerhhh
Aerhhh merged commit 17bfd29 into master Nov 21, 2026
2 checks passed
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