Lukasz Lenart created WW-5854:
---------------------------------
Summary: NumberConverter accepts a locale-grouped out-of-range
value for boxed Integer/Short/Byte and wraps it instead of raising a conversion
error
Key: WW-5854
URL: https://issues.apache.org/jira/browse/WW-5854
Project: Struts 2
Issue Type: Bug
Components: Core
Affects Versions: 7.4.0, 6.12.0
Reporter: Lukasz Lenart
For a boxed numeric target {{NumberConverter.convertValue}} parses the string
with a grouping-aware {{NumberFormat}} and then calls {{isInRange(number,
stringValue, toType)}}. {{isInRange}} re-parses the *original grouped string*
with {{new BigInteger(stringValue)}}; the grouping separator makes that throw
{{NumberFormatException}}, the {{catch}} returns {{true}} (the comment there
still asks "shoult it fail here?") and the value is accepted.
{{DefaultTypeConverter.convertValue}} then narrows with an unchecked cast
({{(int) longValue(value)}}, {{(short)}}, {{(byte)}}), which wraps.
Observed on {{main}}, en\_US locale, through {{XWorkConverter}}:
||input||target||result||
|{{2,147,483,648}}|{{Integer}}|{{-2147483648}}|
|{{32,768}}|{{Short}}|{{-32768}}|
|{{1,000}}|{{Byte}}|{{-24}}|
|{{9,223,372,036,854,775,808}}|{{Long}}|{{Long.MAX_VALUE}} (NumberFormat
returns a Double)|
|{{2147483648}} (ungrouped)|{{Integer}}|{{TypeConversionException}}, as
expected|
|{{1,234}}|{{Integer}}|{{1234}}|
Primitive targets take the other branch and are not affected. The code is
identical on {{main}} and {{support/struts-6-x-x}}; the {{catch}} dates from
the 2015 xwork merge.
h2. Where
{{core/src/main/java/org/apache/struts2/conversion/impl/NumberConverter.java}}
({{convertValue}} boxed branch and {{isInRange}}),
{{core/src/main/java/org/apache/struts2/conversion/impl/DefaultTypeConverter.java}}
(narrowing casts).
h2. Fix
Check the range on the {{Number}} that {{NumberFormat}} produced instead of
re-parsing the grouped string: a {{Long}} result is compared with the target
type's bounds; a {{Double}} result for an integer target means the value did
not fit a long and is out of range. Remove the {{catch}} that returns {{true}}.
{{XWorkConverterTest}} currently covers grouped in-range values only; add the
table above as tests.
This is a conversion-correctness bug: the wrapped value lies inside the target
type's range and could have been submitted directly, and business-rule ranges
remain the job of the range validators.
h2. Source
Reported publicly on the Full Disclosure list, 2026-10-29:
https://seclists.org/fulldisclosure/2026/Nov/4
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)