Fix deserialization of u16 arrays 2023-04-fix-bucket-deser
authorMatt Corallo <git@bluematt.me>
Sun, 16 Apr 2023 21:57:20 +0000 (21:57 +0000)
committerMatt Corallo <git@bluematt.me>
Sun, 16 Apr 2023 21:59:35 +0000 (21:59 +0000)
u16 arrays are used in the historical liquidity range tracker.
Previously, we read them without applying the stride multiple,
reading bytes repeatedly and at an offset, corrupting data as we
go.

This applies the correct stride multiplayer fixing the issue.

lightning/src/util/ser.rs

index 366e6c8cb1efaef3767b0e8d4232c3763915eb20..8056f3bed35569e952c6897a4b999b6e2bf3b1fd 100644 (file)
@@ -596,7 +596,7 @@ impl Readable for [u16; 8] {
                r.read_exact(&mut buf)?;
                let mut res = [0u16; 8];
                for (idx, v) in res.iter_mut().enumerate() {
-                       *v = (buf[idx] as u16) << 8 | (buf[idx + 1] as u16)
+                       *v = (buf[idx*2] as u16) << 8 | (buf[idx*2 + 1] as u16)
                }
                Ok(res)
        }