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

Fix Corruption issue. #524

Merged
merged 1 commit into from
Feb 27, 2023
Merged

Fix Corruption issue. #524

merged 1 commit into from
Feb 27, 2023

Conversation

JemDay
Copy link
Contributor

@JemDay JemDay commented Feb 22, 2023

  • Fixed issue where mutiple serialize/de-serialize operations would result in corrupted data if the data was a protobuf message object.

  • Introduced equality checks for ProtoDataWrapper.

  • Refactored and cleaned up data-wrappers.

Fixes #523

Copy link

@mishap4 mishap4 left a comment

Choose a reason for hiding this comment

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

I am new to the project, but changes look good

Comment on lines 159 to 209
byte[] raw1 = format.serialize(event);
io.cloudevents.CloudEvent act1 = format.deserialize(raw1);
assertThat(event).withFailMessage("Mismatch on 1st round trip").isEqualTo(act1);

// 2nd Round Trip
byte[] raw2 = format.serialize(act1);
io.cloudevents.CloudEvent act2 = format.deserialize(raw2);
assertThat(event).withFailMessage("Mismatch on 2nd round trip").isEqualTo(act2);

// 3rd Time's a charm
byte[] raw3 = format.serialize(act2);
io.cloudevents.CloudEvent act3 = format.deserialize(raw3);
assertThat(event).withFailMessage("Mismatch on 3rd round trip").isEqualTo(act3);
Copy link
Member

Choose a reason for hiding this comment

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

I would compare the actual bytes with each other in addition to the event

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test is more around asserting that the CloudEvent Object is consistent across the various serialize/deserialize operations than the wire-format.

If we wanted to add that level of check I'd suggest re-working the equals() implementation from your prior comment.

Copy link
Member

Choose a reason for hiding this comment

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

What we make sure by comparing additionally raw bytes is that also the equals method is correct

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added new UnitTests to address byte[] equality.

@pierDipi
Copy link
Member

Thanks @JemDay

@JemDay
Copy link
Contributor Author

JemDay commented Feb 23, 2023

I think I'd like to roll-in a fix to address the inconsistencies raised by @mishap4 - that might simplify the implementation a bit more as well.

Comment on lines 159 to 209
byte[] raw1 = format.serialize(event);
io.cloudevents.CloudEvent act1 = format.deserialize(raw1);
assertThat(event).withFailMessage("Mismatch on 1st round trip").isEqualTo(act1);

// 2nd Round Trip
byte[] raw2 = format.serialize(act1);
io.cloudevents.CloudEvent act2 = format.deserialize(raw2);
assertThat(event).withFailMessage("Mismatch on 2nd round trip").isEqualTo(act2);

// 3rd Time's a charm
byte[] raw3 = format.serialize(act2);
io.cloudevents.CloudEvent act3 = format.deserialize(raw3);
assertThat(event).withFailMessage("Mismatch on 3rd round trip").isEqualTo(act3);
Copy link
Member

Choose a reason for hiding this comment

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

What we make sure by comparing additionally raw bytes is that also the equals method is correct

@JemDay
Copy link
Contributor Author

JemDay commented Feb 24, 2023

I will get some additional/refactored tests in tomorrow whilst retaining backward compatibility

@JemDay
Copy link
Contributor Author

JemDay commented Feb 24, 2023

I think the various comments are addressed now ..

There is more change than expected in the ProtobuffFormatTest file as I (foolishly) reformatted to address the review comment ...

…ult in

corrupted data if the data was a protobuf message object.

Introduced equality checks for ProtoDataWrapper.

Refactored and cleaned up data-wrappers.

Signed-off-by: Jem Day <Jem.Day@cliffhanger.com>
Copy link
Member

@pierDipi pierDipi left a comment

Choose a reason for hiding this comment

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

Thank you!

LGTM

@pierDipi pierDipi merged commit 3614a4f into cloudevents:main Feb 27, 2023
pierDipi pushed a commit to pierDipi/sdk-java that referenced this pull request Feb 27, 2023
… several times (cloudevents#524)

Fixed issue where mutiple serialize/de-serialize operations
would result in corrupted data if the data was a protobuf
message object.

- Introduced equality checks for ProtoDataWrapper.
- Refactored and cleaned up data-wrappers.

Fixes cloudevents#523

Signed-off-by: Jem Day <Jem.Day@cliffhanger.com>
pierDipi added a commit that referenced this pull request Feb 27, 2023
… several times (#524) (#525)

Fixed issue where mutiple serialize/de-serialize operations
would result in corrupted data if the data was a protobuf
message object.

- Introduced equality checks for ProtoDataWrapper.
- Refactored and cleaned up data-wrappers.

Fixes #523

Signed-off-by: Jem Day <Jem.Day@cliffhanger.com>
skepticoitusInteruptus pushed a commit to skepticoitusInteruptus/sdk-java that referenced this pull request Mar 23, 2023
… several times (cloudevents#524)

Fixed issue where mutiple serialize/de-serialize operations
would result in corrupted data if the data was a protobuf
message object.

- Introduced equality checks for ProtoDataWrapper.
- Refactored and cleaned up data-wrappers.

Fixes cloudevents#523

Signed-off-by: Jem Day <Jem.Day@cliffhanger.com>
Signed-off-by: Randi Sheaffer-Klass <97033958+skepticoitusInteruptus@users.noreply.github.com>
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.

Protobuf data corruption when CloudEvent is serialized/deserialized several times
3 participants