Repository navigation
Return a decode result from Buffer::copy - #103
Merged
Merged
Conversation
`Buffer::copy` relied on `BSLS_ASSERT` to confirm enough bytes remained before its `memcpy`. Where that assert is compiled out a short buffer read past the end of the backing data; where it is enabled a truncated frame aborted the process. Neither is a reasonable response to bytes that arrive off the wire. Give `copy` an out parameter and a `bool` result, so a caller cannot go on to use a value that was never read. The destination must be exactly as wide as the wire type, checked at compile time, so naming the wrong type can neither truncate the value nor leave the read position part way through a field. `Buffer::consume` truncates to the bytes available. Every decoder in `rmqamqpt` propagates that result, so a truncated payload becomes a decode failure, which `Framer::appendFrame` already reports to `Connection` as a channel exception. `ConfirmSelect::decode` had no length check at all and is covered by the same change. Three value level fixes in the decoders this rewrites: - AMQP packs consecutive `bit` fields into one octet. Those fields are read into a `uint8_t` and masked to the bit they occupy, rather than copied into a `bool`, which is undefined for a byte other than 0 or 1 and let a reserved bit decide the value. - The unsupported `DECIMAL` value reported success without consuming its five octets, leaving the rest of the field table to be read from the wrong offset. It is now consumed and left unset, which re-encodes as `V`, so republishing such headers drops the decimal. - `Types::decodeTimestamp` returns `bool` and uses the checked `bdlt::EpochUtil::convertFromTimeT64` overload, whose unchecked counterpart has an undefined behaviour precondition that a broker supplied value can violate. The rewritten `BasicQoS::decode` guard also drops a stale log message that named `Connection.Tune`.
michalovits
approved these changes
Nov 2, 2026
flamble
marked this pull request as ready for review
November 2, 2026 10:59
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.
Problem statement
Buffer::copyrelied onBSLS_ASSERTto confirm enough bytes remained before itsmemcpy. Where that assert is compiled out a short buffer read past the end of the backing data; where it is enabled a truncated frame aborted the process. Neither is a reasonable response to bytes that arrive off the wire.Proposed changes
Give
copyan out parameter and aboolresult, so a caller cannot go on to use a value that was never read. The destination must be exactly as wide as the wire type, checked at compile time, so naming the wrong type can neither truncate the value nor leave the read position part way through a field.Buffer::consumetruncates to the bytes available.Every decoder in
rmqamqptpropagates that result, so a truncated payload becomes a decode failure, whichFramer::appendFramealready reports toConnectionas a channel exception.ConfirmSelect::decodehad no length check at all and is covered by the same change.Three value level fixes in the decoders this rewrites:
bitfields into one octet. Those fields are read into auint8_tand masked to the bit they occupy, rather than copied into abool, which is undefined for a byte other than 0 or 1 and let a reserved bit decide the value.DECIMALvalue reported success without consuming its five octets, leaving the rest of the field table to be read from the wrong offset. It is now consumed and left unset, which re-encodes asV, so republishing such headers drops the decimal.Types::decodeTimestampreturnsbooland uses the checkedbdlt::EpochUtil::convertFromTimeT64overload, whose unchecked counterpart has an undefined behaviour precondition that a broker supplied value can violate.The rewritten
BasicQoS::decodeguard also drops a stale log message that namedConnection.Tune.