Skip to content

Limit decimals and shorten rejected input in exception messages on 8.1.x - #17

Merged
MoamenEltouny merged 2 commits into
8.1.xfrom
fix/input-limits-8.1.x
Oct 11, 2026
Merged

MoamenEltouny merged 2 commits into
8.1.xfrom
fix/input-limits-8.1.x

Conversation

@MoamenEltouny

Copy link
Copy Markdown
Member

Summary

Fixes the two findings from the security review for the 8.1.x line: $decimals had no upper bound, and exception messages repeated the rejected input in full.

Changes

  • $decimals above 100 throws InvalidArgumentException in Number::format(), Number::compact(), Number::percentage(), Bytes::format(), Money::format() and Money::compact(). Very large values used to exhaust memory with an uncatchable fatal error (Number::format(1.5, PHP_INT_MAX)) or return wrong digits: with a locale, Number::format(1.5, 100000000, false, 'en_US') returned "0".
  • Exception messages quote at most 50 bytes of the value they reject, cut at a character boundary, through a new internal Support\Excerpt helper. This covers Bytes::parse(), Duration::between(), currency codes, invalid locales and MissingIntlExtension. A 1 MB input now gives a message under 100 bytes.
  • Regression tests for the limit (including 100 and PHP_INT_MAX), short and cut messages, multibyte cutting, and the locale and missing-intl paths.
  • The docs, MAINTAINING.md and a 8.1.2 - Unreleased changelog section describe the limit.

Compatibility

Decimals from 0 to 100 format exactly as before. Values above 100 used to crash or print wrong numbers, so rejecting them is a bug fix. Exception message text changed only for inputs longer than 50 bytes.

@MoamenEltouny MoamenEltouny self-assigned this Oct 11, 2026
@MoamenEltouny
MoamenEltouny merged commit 560c871 into 8.1.x Oct 11, 2026
7 checks passed
@MoamenEltouny
MoamenEltouny deleted the fix/input-limits-8.1.x branch October 11, 2026 09:58
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