Skip to content

guard XSSFBUtils wide-string byte length against int overflow#1079

Open
jmestwa-coder wants to merge 1 commit into
apache:trunkfrom
jmestwa-coder:xssfbutils-widestring-overflow
Open

guard XSSFBUtils wide-string byte length against int overflow#1079
jmestwa-coder wants to merge 1 commit into
apache:trunkfrom
jmestwa-coder:xssfbutils-widestring-overflow

Conversation

@jmestwa-coder
Copy link
Copy Markdown
Contributor

readXLWideString and readXLNullableWideString size the string as 2*(int)numChars, which overflows for char counts at or above 0x40000000 read from an .xlsb stream. The wrapped negative length slips past the offset+numBytes > data.length check, so an oversized record throws a raw StringIndexOutOfBoundsException instead of XSSFBParseException, and high-bit counts read the wrong length and desync the record stream. Compute the byte count in long so the bounds check applies before narrowing.

sb.append(new String(data, offset, numBytes, StandardCharsets.UTF_16LE));
numBytes+=4;
return numBytes;
sb.append(new String(data, offset, (int)numBytes, StandardCharsets.UTF_16LE));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should validate before the cast in the sb.append params

sb.append(new String(data, offset, numBytes, StandardCharsets.UTF_16LE));
numBytes+=4;
return numBytes;
sb.append(new String(data, offset, (int)numBytes, StandardCharsets.UTF_16LE));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should validate before the cast in the sb.append params

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.

2 participants