Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate continuation bytes during code point iteration #2855

Merged
merged 1 commit into from
Jan 6, 2024

Conversation

nvmkuruc
Copy link
Collaborator

@nvmkuruc nvmkuruc commented Dec 9, 2023

Description of Change(s)

This change ensures that only continuation bytes (bytes that start with 10) are consumed when incrementing. Consider an algorithm that searches for the ASCII character . in a string. An algorithm that iterates over a UTF-8 string as bytes (using say std::string::find) would check each byte individually and always find any . characters. An algorithm iterating over code points could miss a valid . following an invalid incomplete 2, 3, or 4 character UTF-8 character sequence if continuations are not checked before incrementing.

This change also changes encoding length checks to use ranges instead of shifting. In many compilers, the same or similar assembly is generated, but in gcc 9.3, shifting introduces an additional movzx. As that's the current compiler targeted by OpenUSD's linux build (and #2673 already made a similar switch from shift to range checks), it seems prudent to make a similar switch.

Fixes Issue(s)

  • I have verified that all unit tests pass with the proposed changes
  • I have submitted a signed Contributor License Agreement

@nvmkuruc nvmkuruc changed the title Validate continuation bytes during code point iteration. Validate continuation bytes during code point iteration Dec 9, 2023
@nvmkuruc nvmkuruc force-pushed the continuationbytes branch 8 times, most recently from 3c9a6d7 to 466d53e Compare December 11, 2023 05:28
@jesschimein
Copy link
Contributor

Filed as internal issue #USD-9066

@pixar-oss pixar-oss merged commit a953c7d into PixarAnimationStudios:dev Jan 6, 2024
5 checks passed
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.

3 participants