Fix extractbits invariant for non-byte-aligned bitfields#8860
Open
tautschnig wants to merge 1 commit intodiffblue:developfrom
Open
Fix extractbits invariant for non-byte-aligned bitfields#8860tautschnig wants to merge 1 commit intodiffblue:developfrom
tautschnig wants to merge 1 commit intodiffblue:developfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a crash/invariant violation in the byte-lowering pipeline when unpacking non-byte-aligned bitfields by ensuring generated extractbits operations never exceed the source bitvector width.
Changes:
- Zero-extend non-byte-aligned bitvector sources in
unpack_recup to the next byte boundary before emitting byte-sizedextractbits. - Add a regression test reproducing issue #8581 (CSmith seed minimised via creduce).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/util/lower_byte_operators.cpp |
Pads non-byte-aligned sources via zero-extension so bytewise extractbits stay in-bounds. |
regression/cbmc/extractbits-bitfield-typecast/test.desc |
Adds a regression harness expecting a clean CBMC run (no crash) for the reduced reproducer. |
regression/cbmc/extractbits-bitfield-typecast/main.c |
Minimal C reproducer exercising the problematic unpacking path for a non-byte-aligned bitfield. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
When unpacking a non-byte-aligned bitfield (e.g., 28 bits) into bytes, the unpack_rec function in lower_byte_operators.cpp created byte-sized extractbits operations that could exceed the source bitvector width. For a 28-bit source, the last byte extraction at offset 24 would try to read bits 24-31, but only bits 0-27 exist. The simplifier then merged these adjacent extractbits into a single extractbits(src, 0, bv[32]) from a 28-bit source, violating the DATA_INVARIANT in convert_extractbits. Fix by zero-extending the source to the next byte boundary before creating byte-sized extractbits, so all extractions stay within bounds. Restore the original DATA_INVARIANT that correctly detects malformed extractbits expressions. The regression test was minimised from CSmith seed 1736798452 using creduce. Fixes: diffblue#8581 Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
a15d095 to
439aeed
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #8860 +/- ##
========================================
Coverage 80.01% 80.01%
========================================
Files 1703 1703
Lines 188396 188406 +10
Branches 73 73
========================================
+ Hits 150738 150758 +20
+ Misses 37658 37648 -10 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
When unpacking a non-byte-aligned bitfield (e.g., 28 bits) into bytes, the unpack_rec function in lower_byte_operators.cpp created byte-sized extractbits operations that could exceed the source bitvector width. For a 28-bit source, the last byte extraction at offset 24 would try to read bits 24-31, but only bits 0-27 exist. The simplifier then merged these adjacent extractbits into a single extractbits(src, 0, bv[32]) from a 28-bit source, violating the DATA_INVARIANT in convert_extractbits.
Fix by zero-extending the source to the next byte boundary before creating byte-sized extractbits, so all extractions stay within bounds. Restore the original DATA_INVARIANT that correctly detects malformed extractbits expressions.
The regression test was minimised from CSmith seed 1736798452 using creduce.
Fixes: #8581