fix: return a decode error for malformed material description - #85
Open
lucasmcdonald3 wants to merge 6 commits into
Open
fix: return a decode error for malformed material description#85lucasmcdonald3 wants to merge 6 commits into
lucasmcdonald3 wants to merge 6 commits into
Conversation
customS3Decoder consumed a high-bit (>127) byte together with the following byte without confirming that a following byte exists. An incomplete multi-byte sequence at the end of the (mime-decoded) material description could therefore read past the end of the string. Bound-check before reading the pair and return a clean decode error for an incomplete sequence. The decrypt middleware already surfaces decode errors, so a malformed material description becomes a normal error return. Applied identically to the v3 and v4 modules. Adds regression tests to both modules covering a trailing high byte, a single high byte, and RFC 2047 mime-encoded variants, plus valid-JSON negative controls.
lucasmcdonald3
force-pushed
the
fix/material-description-decoding-robustness
branch
from
July 27, 2026 16:44
c0f28b5 to
c667124
Compare
There was a problem hiding this comment.
Pull request overview
This PR hardens customS3Decoder in both v3 and v4 clients by preventing an out-of-bounds read (panic) when the decoded material description ends with an unmatched high-bit byte, returning a decode error instead.
Changes:
- Add a bounds check in
customS3Decoderto reject material descriptions that end mid “byte-pair”. - Add new unit tests in both v3 and v4 to ensure malformed/truncated inputs return an error (and don’t panic).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| v4/client/decrypt_middleware.go | Adds a guard to avoid out-of-bounds access when decoding malformed material descriptions. |
| v4/client/decrypt_middleware_matdesc_test.go | Adds tests asserting malformed material descriptions produce decode errors. |
| v3/client/decrypt_middleware.go | Mirrors the v4 decoder hardening in the v3 client. |
| v3/client/decrypt_middleware_matdesc_test.go | Mirrors the v4 decoder tests for v3. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Drop two cases that don't exercise a distinct code path: - "single 0x80 byte" duplicates the "single high byte" (0xFF) guard path - "mime-encoded abc+ff" decodes to the same bytes as "trailing high byte" Remaining cases cover the guard firing on the first byte, after a completed pair (3-byte rune), and on mime.DecodeHeader output.
lucasmcdonald3
pushed a commit
to aws/amazon-s3-encryption-client-python
that referenced
this pull request
Jul 27, 2026
…erify Go: aws/amazon-s3-encryption-client-go#85 (aea828bfeffe4bde5afbbfebf8e08ef644a649ad). PHP: fork PR#1 (411d948378d7412f94d8c4fb23f64442b9a90f0f). Ruby: fork PR#1 (1139087e071c971308d107352cc41219710886c9).
lucasmcdonald3
pushed a commit
to aws/amazon-s3-encryption-client-python
that referenced
this pull request
Jul 27, 2026
…erify Go: aws/amazon-s3-encryption-client-go#85 (aea828bfeffe4bde5afbbfebf8e08ef644a649ad). PHP: fork PR#1 (411d948378d7412f94d8c4fb23f64442b9a90f0f). Ruby: fork PR#1 (1139087e071c971308d107352cc41219710886c9).
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.
Issue #, if available:
Description of changes:
Fix
customS3Decoderpanic when reading a tampered, invalid material descriptionBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Check any applicable: