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

Port fix: Fix JSPB binary utf8 decoding and validate by default (breaking change) #191

Merged
merged 2 commits into from
Jul 16, 2024

Conversation

dibenede
Copy link
Contributor

Our prior behavior was extremely undefined when confronted with errors, it would read out of bounds, accept overlong encodings, skip over out of range bytes, compose out of range codepoints. The new implementation always detects and handles errors consistently by either throwing or using replacement characters (� aka \uFFFD)

This also adds support for aligning with the proto3 spec to the code generator which requires that parsing fail for proto3 messages with invalid utf8 payloads for string fields. For now, actual failing is disabled via the goog.define jspb.binary.ENFORCE_UTF8 which is set to NEVER. A future change will flip this to DEFAULT.

Copy link
Contributor

@lukesandberg lukesandberg left a comment

Choose a reason for hiding this comment

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

Can you ammend the commit description to clarify that we will now validate utf8 bytes by default

@@ -354,7 +354,7 @@ describe('binaryDecoderTest', () => {

const decoder = jspb.BinaryDecoder.alloc(encoder.end());

expect(decoder.readString(len)).toEqual(long_string);
expect(decoder.readString(len, true)).toEqual(long_string);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
expect(decoder.readString(len, true)).toEqual(long_string);
expect(decoder.readString(len, /* enforceUtf8= */ true)).toEqual(long_string);

binary/decoder_test.js Outdated Show resolved Hide resolved
binary/decoder_test.js Outdated Show resolved Hide resolved
binary/decoder_test.js Outdated Show resolved Hide resolved
binary/decoder_test.js Outdated Show resolved Hide resolved
binary/reader.js Show resolved Hide resolved
@dibenede dibenede changed the title Port fix: Fix JSPB binary utf8 decoding to be spec compliant. Port fix: Fix JSPB binary utf8 decoding to be spec compliant (breaking change) Jun 17, 2024
@dibenede dibenede changed the title Port fix: Fix JSPB binary utf8 decoding to be spec compliant (breaking change) Port fix: Fix JSPB binary utf8 decoding and validate by default (breaking change) Jun 17, 2024
@ribrdb
Copy link

ribrdb commented Jul 16, 2024

What's the status of this? Is there a reason it hasn't been merged?

@dibenede
Copy link
Contributor Author

What's the status of this? Is there a reason it hasn't been merged?

This will be going in shortly. I wanted to cut a release beforehand, which is now done. However, that was slow to get out the door due to release infrastructure issues.

Our prior behavior was extremely undefined when confronted with errors, it would read out of bounds, accept overlong encodings, skip over out of range bytes, compose out of range codepoints. The new implementation always detects and handles errors consistently by either throwing or using replacement characters (� aka \uFFFD)

This also adds support for aligning with the proto3 spec to the code generator which requires that parsing fail for proto3 messages with invalid utf8 payloads for string fields. For now, actual failing is disabled via the goog.define jspb.binary.ENFORCE_UTF8 which is set to NEVER. A future change will flip this to DEFAULT.
Co-authored-by: Luke Sandberg <lukesandberg@users.noreply.github.com>
@dibenede dibenede merged commit 27d4277 into protocolbuffers:main Jul 16, 2024
4 checks passed
@dibenede dibenede deleted the fix-over-read branch July 16, 2024 17:07
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