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

[C++] Add padding characters to base64 encoded protobuf native schema #11492

Merged

Conversation

BewareMyPower
Copy link
Contributor

Motivation

#11388 added support for protobuf native schema in C++ client. The implementation serializes a protobuf generated class' descriptor to a Base64 encoded string. However, it doesn't add the padding characters while the broker side requires the padding characters. Therefore, if the Base64 encoded string needs the padding characters, the broker will fail to deserialize:

com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type byte[] from String "": Unexpected end of base64-encoded String: base64 variant 'MIME-NO-LINEFEEDS' expects padding (one or more '=' characters) at the end. This Base64Variant might have been incorrectly configured

See https://en.wikipedia.org/wiki/Base64#Decoding_Base64_with_padding for the Base64 with padding.

Modifications

  • Add the padding = characters if the Base64 encoded string's length is not a multiple of four.
  • Add a PaddingDemo.proto to test the above case to ensure that broker can validate the schema string.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests ProtobufNativeSchemaTest. testBase64WithPadding.

@BewareMyPower BewareMyPower added type/bug The PR fixed a bug or issue reported a bug component/c++ doc-not-needed Your PR changes do not impact docs labels Jul 29, 2021
@BewareMyPower BewareMyPower self-assigned this Jul 29, 2021
@BewareMyPower
Copy link
Contributor Author

/pulsarbot run-failure-checks

@codelipenghui codelipenghui added this to the 2.9.0 milestone Jul 29, 2021
@codelipenghui codelipenghui merged commit c798eaf into apache:master Jul 30, 2021
@BewareMyPower BewareMyPower deleted the bewaremypower/cpp-protobuf-fix branch August 4, 2021 03:21
bharanic-dev pushed a commit to bharanic-dev/pulsar that referenced this pull request Mar 18, 2022
…apache#11492)

### Motivation

apache#11388 added support for protobuf native schema in C++ client. The implementation serializes a protobuf generated class' descriptor to a Base64 encoded string. However, it doesn't add the padding characters while the broker side requires the padding characters. Therefore, if the Base64 encoded string needs the padding characters, the broker will fail to deserialize:

> com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `byte[]` from String "": Unexpected end of base64-encoded String: base64 variant 'MIME-NO-LINEFEEDS' expects padding (one or more '=' characters) at the end. This Base64Variant might have been incorrectly configured

See https://en.wikipedia.org/wiki/Base64#Decoding_Base64_with_padding for the Base64 with padding.

### Modifications

- Add the padding `=` characters if the Base64 encoded string's length is not a multiple of four.
- Add a `PaddingDemo.proto` to test the above case to ensure that broker can validate the schema string.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-not-needed Your PR changes do not impact docs type/bug The PR fixed a bug or issue reported a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants