fix(certifier): check wire message size before JSON deserialisation #1523
Open
atharrva01 wants to merge 2 commits intohyperledger-labs:mainfrom
Open
fix(certifier): check wire message size before JSON deserialisation #1523atharrva01 wants to merge 2 commits intohyperledger-labs:mainfrom
atharrva01 wants to merge 2 commits intohyperledger-labs:mainfrom
Conversation
Adds MaxWireMessageBytes (2 MiB) and uses ReceiveRaw() to reject oversized messages before json.Unmarshal, preventing heap spikes from allocate-then-reject. Injects sessionFactory for unit testability. Signed-off-by: atharrva01 <atharvaborade568@gamil.com>
Contributor
Author
|
caught oversized payloads before deserialization using |
Signed-off-by: atharrva01 <atharvaborade568@gamil.com>
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.
Follow-on to #1498 based on your @adecaro's review feedback.
The
MaxRequestBytescheck I added in #1498 ran after full JSON deserialization , so a 500 MiB payload would still spike the heap before getting rejected. The fix needs to happen earlier.I can't touch the transport layer directly, but
ReceiveRaw()gets us close enough: now we checklen(raw) > MaxWireMessageBytesbefore ever callingjson.Unmarshal, so an oversized message gets dropped before any allocations for the IDs slice orRequestfield.To keep this unit-testable without a real FSC session, I added a
sessionFactoryfield (defaults tosession.JSON) so tests can inject a fake that returns preset raw bytes.Changes:
config.go, addsMaxWireMessageBytes = MaxRequestBytes * 2service.go, switches toReceiveRaw+ size guard + manual unmarshal; addssessionFactoryservice_test.go, 4 new tests: oversized reject, at-limit pass-through, transport errors, constant relationship