Skip to content

MINOR: Reject truncated UTF-8 sequences in Text.validateUTF8 - #1522

Merged
jbonofre merged 1 commit into
apache:mainfrom
Arawoof06:utf8-truncated-sequence
Nov 25, 2026
Merged

jbonofre merged 1 commit into
apache:mainfrom
Arawoof06:utf8-truncated-sequence

Conversation

@Arawoof06

Copy link
Copy Markdown
Contributor

What's Changed

Text.validateUTF8Internal walks the bytes with a lead-byte/trail-byte state machine, but when the loop runs out of input it returns success even if it is still waiting for trail bytes. A value that ends partway through a multi-byte sequence, such as C3, E2 82 or F0 9F 98, is reported as valid UTF-8.

That helper backs validateScalars in VarCharVector, LargeVarCharVector and ViewVarCharVector, so ValueVectorUtility.validateFull (and ArrowReader with setValidateBatches(true), the option recommended for untrusted IPC input) accepts a Utf8 column holding invalid UTF-8. Lead bytes that are invalid on their own (FF FE) were already rejected, which is why the existing tests pass.

The fix reports the end position as malformed when the input ends outside the lead-byte state. Valid input is unaffected. testValidateTruncatedUTF8 in TestValidateVectorFull covers truncated 2, 3 and 4 byte sequences for VarChar and LargeVarChar. It fails without the change and passes with it, and the rest of the vector tests still pass.

@jbonofre jbonofre added the bug-fix PRs that fix a big. label Nov 25, 2026
@github-actions github-actions Bot added this to the 20.1.0 milestone Nov 25, 2026

@jbonofre jbonofre left a comment

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.

Thanks for the fix! I checked the change against the state machine: valid sequence always end back in LEAD_BYTE and empty input still passes, so this only rejects values that end partway through a multi-byte character.

LGTM!

@apache apache deleted a comment from github-actions Bot Nov 25, 2026
@jbonofre
jbonofre merged commit 10c55b9 into apache:main Nov 25, 2026
22 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix PRs that fix a big.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants