Skip to content

Fix UB in cbor_value_get_int64() with out-of-range inputs - #349

Open
thiagomacieira wants to merge 1 commit into
intel:mainfrom
thiagomacieira:Fix_UB_in_cbor_value_get_int64_with_out_of_range_inputs
Open

thiagomacieira wants to merge 1 commit into
intel:mainfrom
thiagomacieira:Fix_UB_in_cbor_value_get_int64_with_out_of_range_inputs

Conversation

@thiagomacieira

Copy link
Copy Markdown
Member

This function and cbor_value_get_int() are documented to "silently truncate" the values out of range and that untrusted input should be checked with their _checked() versions. However, it only truncated as a side-effect of UB, in the typical build. We cannot depend on that.

The simplest fix is to just use unsigned arithmetic to do exactly what we were doing. The generated assembly will be exactly what we want and probably what was being generated anyway.

Fixes #347.

This function and `cbor_value_get_int()` are documented to "silently
truncate" the values out of range and that untrusted input should be
checked with their `_checked()` versions. However, it only truncated as
a side-effect of UB, in the typical build. We cannot depend on that.

The simplest fix is to just use unsigned arithmetic to do exactly what
we were doing. The generated assembly will be exactly what we want and
probably what was being generated anyway.

Fixes intel#347.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
@thiagomacieira
thiagomacieira force-pushed the Fix_UB_in_cbor_value_get_int64_with_out_of_range_inputs branch from 6bee071 to cf7f4d0 Compare October 27, 2026 16:28

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Signed overflow in cbor_value_get_int64() / cbor_value_get_int() for out-of-range negative integers

1 participant