Skip to content

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

Open
Arawoof06 wants to merge 1 commit into
apache:mainfrom
Arawoof06:utf8-truncated-sequence
Open

Arawoof06 wants to merge 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.

@github-actions

Copy link
Copy Markdown

Thank you for opening a pull request!

Please label the PR with one or more of:

  • bug-fix
  • chore
  • dependencies
  • documentation
  • enhancement

Also, add the 'breaking-change' label if appropriate.

See CONTRIBUTING.md for details.

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.

1 participant