On Mon, 12 Jan 2026 19:43:57 GMT, Damon Nguyen <[email protected]> wrote:

>> There were three concerns with the previous changes to `XbmImageDecoder`.
>> 1. Only the first line of the bit array was read.
>> 2. The regex was incorrect because it used `[]` instead of `()` for some 
>> grouping.
>> 3. The ordering of the width and height in the xbm file was too strict and 
>> had to be width first, then height.
>> 
>> To fix these issues, I have:
>> 1. Used a StringBuilder to append lines of the bit array to parse the entire 
>> array at once. This required changing the parsing loop and moving some code.
>> 2. Updated the regex to capture starting whitespace, optionally start with 
>> `0x`, include all chars/digits/punctuation (minus `,` and `};`) instead of 
>> just valid hex digits, and end with either `,` or `};`. This also allows for 
>> incorrect hex values such as `0x12345abcde` to be detected since the new 
>> regex allows for multiple chars after the `0x` until the next delimiter is 
>> found. This is accounted for in the test xbm files.
>> 3. Determined width or height based off of ending letters (`th` or `t`). 
>> This is similar to 
>> https://github.com/openjdk/jdk/blob/jdk-26+10/src/java.desktop/share/classes/sun/awt/image/XbmImageDecoder.java#L109-L112.
>> 
>> A new method is added to `XBMDecoderTest.java` to better check that the bit 
>> array parsing works. This method checks for non-empty pixel data.
>> 
>> A new xbm file is also added to check for the case where `0xAB+` exists in 
>> the bit array. This should be invalid, and the previous regex would allow 
>> this to pass. 
>> 
>> All tests pass with the new changes made here.
>
> Damon Nguyen has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Add test for empty bit array

New xbm files added to explicitly test for an invalid empty bit array as well 
as a valid bit array where there are additional newlines beyond the initial 
newline stated in the original bug.

The test correctly fails the invalid empty file and passes the new valid 
multiline xbm file. The overall test passes after the changes.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/29120#issuecomment-3740249196

Reply via email to