fix!: decode data_base64 as Uint8Array instead of Uint32Array#644
Open
saschabratton wants to merge 1 commit intocloudevents:mainfrom
Open
fix!: decode data_base64 as Uint8Array instead of Uint32Array#644saschabratton wants to merge 1 commit intocloudevents:mainfrom
saschabratton wants to merge 1 commit intocloudevents:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
parseStructured()decodesdata_base64into aUint32Arrayinstead ofUint8Array, producing binary data with a corrupted underlyingArrayBuffer.The existing code:
This stores each byte value (0–255) in a 32-bit element. The numeric values are correct, so consumers using
Buffer.from(typedArray)(which copies values element-by-element) happen to get the right bytes. But any consumer that reads the underlyingArrayBufferdirectly (such as protobuf libraries) sees 4 bytes per element with null-byte padding, resulting in silently corrupted data.Uint32Arraywas introduced as the SDK's internal binary representation around #491 / #494, which fixed the encoding direction (creating CloudEvents with binary data). The decoding path inparseStructuredwas never updated. Notably, the SDK's ownbase64AsBinary()inevent/validation.tsalready correctly usesUint8Array.Proposed Changes
new Uint32Array(Buffer.from(...))with a call to the existingbase64AsBinary()helper, which returns a properUint8ArrayUint32ArraytoUint8Arrayto matchevent.datais aUint8Arraywith correctbuffer.byteLengthBreaking change note
I have flagged this PR as a breaking change because it changes the runtime type of
event.datafromUint32ArraytoUint8Arrayfor structured-mode CloudEvents withdata_base64. Code that checksinstanceof Uint32Arrayor relies onBYTES_PER_ELEMENT === 4would break.However, the current
Uint32Arraybehavior is a bug andUint8Arrayis the correct type for binary data. It's unlikely any consumer intentionally depends onUint32Array. So this could potentially be safe as a patch/minor fix rather than requiring a major version bump.Fixes: #643