Date: Tue, 3 Nov 2026 21:30:49 +0000
On 03/11/2026 18:48, Rainer Deyke via Std-Proposals wrote:
>
>
> On 11/3/26 18:32, Sebastian Wittmeier via Std-Proposals wrote:
>> 1b) The correct image size was the responsibility of the caller. The decoder still checked the precondition and found an error.
>
> If it's a true precondition failure, then it's too late to do anything about it, so the decoder might as well not bother. Precondition violation = undefined behavior = the program is no longer in a valid state. If the caller wants a safety check on the image size, the place for that check is in a wrapper around the function, not inside it.
>
> Conversely, if the decoder checks the image size and reports an error back to the caller in a form that the caller can use, then this is not a true precondition failure. It's an expected error path that should be defined, documented and tested.
>
>> 2b) The correct image size is not known beforehand, but the overall system development group/team should have made sure that only working images are loaded. So it is neither the responsibility of the caller, nor the callee, but of the organisation.
>
> The program should not make assumptions about its environment (beyond "the CPU is working" and "memory bits don't flip randomly"). Correctly sized externally stored images can and should be checked, ideally before the plane takes off.
>
>
Along similar lines to what Thiago stated.
Where compressed images are known, they can be decoded through the software to verify that they are *all* supported and not overrunning. We would typically do this for all available data files and all supported configurations. This could involve many separate executions, as well as integration testing where the same software execution decodes multiple files.
The problem arises when we encounter a compressed image that was not included in the verification process, and which may decompress to a larger buffer size than the fixed-size buffer can accommodate.
This could happen in two scenarios:
A) A file was inadvertently missed during verification.
B) A file is downloaded at runtime and was not available during the original verification process.
So what happens if such a file gets to ImageDecoder and pre() or contract_assert() is used to be certain there is enough space to decode it?
This thread started with Thiago's point that execution should not continue after a precondition violation and should not throw.
It feels like C++ Contracts should not be used for this, a regular check that there is enough buffer space should be added, and an exception thrown or error code returned instead.
The only other alternative is P4021 compile_assert, which checks the code handles at compile-time that the buffer will never be overflowed by expressing that the array subscript must never be larger than a max_size.
Regards
Jonathan
>
>
> On 11/3/26 18:32, Sebastian Wittmeier via Std-Proposals wrote:
>> 1b) The correct image size was the responsibility of the caller. The decoder still checked the precondition and found an error.
>
> If it's a true precondition failure, then it's too late to do anything about it, so the decoder might as well not bother. Precondition violation = undefined behavior = the program is no longer in a valid state. If the caller wants a safety check on the image size, the place for that check is in a wrapper around the function, not inside it.
>
> Conversely, if the decoder checks the image size and reports an error back to the caller in a form that the caller can use, then this is not a true precondition failure. It's an expected error path that should be defined, documented and tested.
>
>> 2b) The correct image size is not known beforehand, but the overall system development group/team should have made sure that only working images are loaded. So it is neither the responsibility of the caller, nor the callee, but of the organisation.
>
> The program should not make assumptions about its environment (beyond "the CPU is working" and "memory bits don't flip randomly"). Correctly sized externally stored images can and should be checked, ideally before the plane takes off.
>
>
Along similar lines to what Thiago stated.
Where compressed images are known, they can be decoded through the software to verify that they are *all* supported and not overrunning. We would typically do this for all available data files and all supported configurations. This could involve many separate executions, as well as integration testing where the same software execution decodes multiple files.
The problem arises when we encounter a compressed image that was not included in the verification process, and which may decompress to a larger buffer size than the fixed-size buffer can accommodate.
This could happen in two scenarios:
A) A file was inadvertently missed during verification.
B) A file is downloaded at runtime and was not available during the original verification process.
So what happens if such a file gets to ImageDecoder and pre() or contract_assert() is used to be certain there is enough space to decode it?
This thread started with Thiago's point that execution should not continue after a precondition violation and should not throw.
It feels like C++ Contracts should not be used for this, a regular check that there is enough buffer space should be added, and an exception thrown or error code returned instead.
The only other alternative is P4021 compile_assert, which checks the code handles at compile-time that the buffer will never be overflowed by expressing that the array subscript must never be larger than a max_size.
Regards
Jonathan
Received on 2026-11-03 21:30:52
