Skip to content

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Oct 22, 2025

🤖 New release

  • deku_derive: 0.20.0 -> 0.20.1
  • deku: 0.20.0 -> 0.20.1 (✓ API compatible changes)
Changelog

deku

0.20.1 - 2025-11-13

Other

  • Add DekuSize impl (#618)
  • Improved documentation on how endian etc. interacts with ctx (#623)
  • Lift alloc requirement for bits feature (#614)
  • Update stable trybuild (#619)
  • add thumbv6m-none-eabi target to ensure_no_std step (#616)
  • update release-plz.toml
  • release v0.20.0 (#610)


This PR was generated with release-plz.

@github-actions github-actions bot force-pushed the release-plz-2025-10-22T18-06-39Z branch 3 times, most recently from bb514b1 to 20ac1eb Compare November 11, 2025 14:03
@github-actions github-actions bot force-pushed the release-plz-2025-10-22T18-06-39Z branch from 20ac1eb to 9cd0b33 Compare November 13, 2025 00:45
@sharksforarms
Copy link
Owner

sharksforarms commented Nov 14, 2025

@amboar @wcampbell0x2a technically #614 doesn't break old code/compatibility right? would you agree in a patch bump or should we do a 0.21 release

@amboar
Copy link
Contributor

amboar commented Nov 14, 2025

@sharksforarms nothing should break, no. The test suite changes were mainly to accommodate changes to reported formatted strings in errors, and the reduction in allocation count.

@wcampbell0x2a
Copy link
Collaborator

@amboar @wcampbell0x2a technically #614 doesn't break old code/compatibility right? would you agree in a patch bump or should we do a 0.21 release

Should be semver compatible.

@amboar
Copy link
Contributor

amboar commented Nov 19, 2025

I think there might be an unintended change in behaviour between v0.20.0 and master for bit_order = "lsb" on some structs. Glimpsed it when testing some other things, and it's clearly not caught by the current test suite, so needs some further investigation.

@amboar
Copy link
Contributor

amboar commented Nov 24, 2025

This fails after #614 but passes if it's reverted:

#[test]
fn test_misaligned_pad_bits_aaelf32_flags() {
    #[derive(Debug, DekuRead, DekuWrite, PartialEq)]
    #[deku(endian = "little", bit_order = "lsb")]
    pub struct AaElf32Flags {
        #[deku(bits = "1", pad_bits_before = "9")]
        ef_arm_abi_float_soft: bool,
        #[deku(bits = "1")]
        ef_arm_abi_float_hard: bool,
        #[deku(bits = "1", pad_bits_before = "11")]
        ef_arm_gccmask: bool,
        #[deku(bits = "1")]
        ef_arm_be8: bool,
        ef_arm_abimask: u8,
    }

    let word = 83886592u32;
    let bytes = word.to_le_bytes();
    let (_, flags) = AaElf32Flags::from_bytes((&bytes, 0)).unwrap();
    assert_eq!(
        AaElf32Flags {
            ef_arm_abi_float_soft: true,
            ef_arm_abi_float_hard: false,
            ef_arm_gccmask: false,
            ef_arm_be8: false,
            ef_arm_abimask: 5,
        },
        flags
    );
}

Looks like I missed specifying some invariants when using seek:

> RUST_LOG=trace cargo test --no-default-features --features=alloc,bits,logging --test test_lsb_le -- test_misaligned_pad_bits_aaelf32_flags
    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.03s
     Running tests/test_lsb_le.rs (target/debug/deps/test_lsb_le-f72cea0c554eeb76)

running 1 test
[2025-11-24T01:58:46Z TRACE deku::reader] skip_bits: 9
[2025-11-24T01:58:46Z TRACE deku::reader] seek: Current(1)
[2025-11-24T01:58:46Z TRACE deku::reader] read_bits_into: Lsb0, 1
[2025-11-24T01:58:46Z TRACE test_lsb_le] Reading: AaElf32Flags.ef_arm_abi_float_soft
[2025-11-24T01:58:46Z TRACE deku::reader] read_bits_into: Lsb0, 1
[2025-11-24T01:58:46Z TRACE test_lsb_le] Reading: AaElf32Flags.ef_arm_abi_float_hard
[2025-11-24T01:58:46Z TRACE deku::reader] read_bits_into: Lsb0, 1
[2025-11-24T01:58:46Z TRACE deku::reader] skip_bits: 11
[2025-11-24T01:58:46Z TRACE deku::reader] read_bits_into: Lsb0, 3
[2025-11-24T01:58:46Z TRACE deku::reader] seek: Current(1)
[2025-11-24T01:58:46Z TRACE deku::reader] read_bits_into: Lsb0, 0
[2025-11-24T01:58:46Z TRACE test_lsb_le] Reading: AaElf32Flags.ef_arm_gccmask
[2025-11-24T01:58:46Z TRACE deku::reader] read_bits_into: Lsb0, 1
[2025-11-24T01:58:46Z TRACE test_lsb_le] Reading: AaElf32Flags.ef_arm_be8
[2025-11-24T01:58:46Z TRACE deku::reader] read_bits_into: Lsb0, 1
[2025-11-24T01:58:46Z TRACE test_lsb_le] Reading: AaElf32Flags.ef_arm_abimask
[2025-11-24T01:58:46Z TRACE deku::reader] read_bits_into: Lsb0, 8
test test_misaligned_pad_bits_aaelf32_flags ... FAILED

After


[2025-11-24T01:58:46Z TRACE deku::reader] skip_bits: 11
[2025-11-24T01:58:46Z TRACE deku::reader] read_bits_into: Lsb0, 3

the current position is not byte-aligned - we've only read 14 bits, so it's incorrect to seek at that point. The requested padding is 11 bits and is incorrectly split into 3 and 8; it should rather be 5 (to become byte-aligned with respect to the already-consumed bits) and then 6, which cannot be seeked, however a read is needed to satisfy the request.

@amboar
Copy link
Contributor

amboar commented Nov 24, 2025

[I] 1 andrew@heihei ~/s/g/s/deku (bit-order-lsb) [101]> git diff
diff --git a/src/reader.rs b/src/reader.rs
index 22b212fb8e1d..bbe0ebc4784e 100644
--- a/src/reader.rs
+++ b/src/reader.rs
@@ -207,6 +207,7 @@ impl<R: Read + Seek> Reader<R> {
 
             // first, seek with bytes
             if bytes_amt != 0 {
+                debug_assert_eq!(self.bits_read % 8, 0);
                 self.seek(SeekFrom::Current(
                     i64::try_from(bytes_amt).expect("could not convert seek usize into i64"),
                 ))
[I] 1 andrew@heihei ~/s/g/s/deku (bit-order-lsb)> cargo test --no-default-features --features=alloc,bits,logging --test test_lsb_le -- test_misaligned_pad_bits_aaelf32_flags
    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.03s
     Running tests/test_lsb_le.rs (target/debug/deps/test_lsb_le-f72cea0c554eeb76)

running 1 test
test test_misaligned_pad_bits_aaelf32_flags ... FAILED

failures:

---- test_misaligned_pad_bits_aaelf32_flags stdout ----

thread 'test_misaligned_pad_bits_aaelf32_flags' (131091) panicked at /home/andrew/src/github.com/sharksforarms/deku/src/reader.rs:210:17:
assertion `left == right` failed
  left: 6
 right: 0
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    test_misaligned_pad_bits_aaelf32_flags

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 8 filtered out; finished in 0.00s

error: test failed, to rerun pass `--test test_lsb_le`

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.

4 participants