Conversation
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The narrowly scoped change correctly eliminates signed-shift undefined behavior without changing macro values.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes undefined behavior when constructing IPC4 notification event IDs while preserving existing values.
Changes:
- Casts magic constants to
uint32_tbefore left-shifting.
| File | Description |
|---|---|
src/include/ipc4/header.h |
Makes IPC4 notification magic-value shifts unsigned. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
abonislawski
approved these changes
Oct 2, 2026
SOF_IPC4_NOTIFY_MODULE_EVENTID_ALSA_MAGIC_VAL and SOF_IPC4_NOTIFY_MODULE_EVENTID_COMPR_MAGIC_VAL are defined as (uint32_t)(0xA15A << 16) and (uint32_t)(0xC0C0 << 16). Both literals have bit 15 set, so the int shift produces a value above INT_MAX before the cast is applied, which is undefined behaviour (UBSan: "left shift of 41306 by 16 places cannot be represented in type 'int'", reported from tdfb_ipc4.c). GCC and clang currently wrap, so the resulting values are correct, but the expression is still ill-formed. Cast to uint32_t before shifting. The macro values are unchanged. Found by the IPC4 libFuzzer campaign with -fsanitize=undefined. Signed-off-by: Tomasz Leman <tomasz.m.leman@intel.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.
SOF_IPC4_NOTIFY_MODULE_EVENTID_ALSA_MAGIC_VAL and
SOF_IPC4_NOTIFY_MODULE_EVENTID_COMPR_MAGIC_VAL are defined as (uint32_t)(0xA15A << 16) and (uint32_t)(0xC0C0 << 16). Both literals have bit 15 set, so the int shift produces a value above INT_MAX before the cast is applied, which is undefined behaviour (UBSan: "left shift of 41306 by 16 places cannot be represented in type 'int'", reported from tdfb_ipc4.c). GCC and clang currently wrap, so the resulting values are correct, but the expression is still ill-formed.
Cast to uint32_t before shifting. The macro values are unchanged.
Found by the IPC4 libFuzzer campaign with -fsanitize=undefined.