henry3260 opened a new pull request, #11167:
URL: https://github.com/apache/ozone/pull/11167

   ## What changes were proposed in this pull request?
   
   `StorageSize.parse()` trims its input, but then computes the substring end
   offset from the *untrimmed* string:
   
   ```java
   String sanitizedValue = value.trim().toLowerCase(Locale.ENGLISH);
   ...
   sanitizedValue.substring(0, value.length() - suffix.length());
   ```
   
   The offset is shifted right by however many whitespace characters `trim()`
   removed, so any surrounding whitespace breaks parsing:
   
   | Input | Result |
   | --- | --- |
   | `"10MB"` | 10.0 megabytes |
   | `" 10MB"` | `NumberFormatException: For input string: "10m"` |
   | `"  128MB  "` | `StringIndexOutOfBoundsException: begin 0, end 7, length 
5` |
   
   This is reachable from configuration, since 
`ConfigurationSource.getStorageSize()`
   reads the value with `get()` rather than `getTrimmed()`, and XML values are
   commonly indented:
   
   ```xml
   <property>
     <name>ozone.scm.container.size</name>
     <value>
       5GB
     </value>
   </property>
   ```
   
   The out-of-bounds case is also not caught by the `parse(String, StorageUnit)`
   fallback, which only catches `IllegalArgumentException`.
   
   The fix is one line: derive the offset from `sanitizedValue.length()`.
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/HDDS-16348
   
   ## How was this patch tested?
   
   New unit test `TestStorageSize` in `hadoop-hdds/config`, covering whitespace
   shorter than, equal to, and longer than the unit suffix being stripped, plus
   the `parse(String, StorageUnit)` overload. All three failure modes reproduce
   against the unpatched code and pass with the fix.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to