Skip to content

Commit

Permalink
Replace BitsSignedB{32,64}Le with better BitsSignedShiftB{32,64}Le
Browse files Browse the repository at this point in the history
Note: BitsSignedB{32,64}Le were removed in the previous commit 43d8b74

According to my tests, new formats BitsSignedShiftB{32,64}Le have better
detection capabilities than their predecessors. Old tests only detected
kaitai-io/kaitai_struct_javascript_runtime@1f8dd95a,
but did not catch the bug when I intentionally change the appropriate
unsigned right shift `>>>` to signed `>>` in the new `readBitsIntLe` impl
introduced in kaitai-io/kaitai_struct#949. Tests
added in this commit reveal both of these errors.
  • Loading branch information
generalmimon committed Mar 12, 2022
1 parent 43d8b74 commit b7e567f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
11 changes: 11 additions & 0 deletions formats/bits_signed_shift_b32_le.ksy
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Make sure that languages with 32-bit operators (JavaScript) use *unsigned*
# (aka zero-fill) right shift, not signed (sign-propagating) right shift. This
# test will fail if a signed shift is used.
meta:
id: bits_signed_shift_b32_le
bit-endian: le
seq:
- id: a
type: b31
- id: b
type: b9
11 changes: 11 additions & 0 deletions formats/bits_signed_shift_b64_le.ksy
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Make sure that languages with 64-bit operators (Java, PHP) use *unsigned* (aka
# zero-fill) right shift, not signed (sign-propagating) right shift. This test
# will fail if a signed shift is used.
meta:
id: bits_signed_shift_b64_le
bit-endian: le
seq:
- id: a
type: b63
- id: b
type: b9
7 changes: 7 additions & 0 deletions spec/ks/bits_signed_shift_b32_le.kst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
id: bits_signed_shift_b32_le
data: bits_signed_shift_b32_le.bin
asserts:
- actual: a
expected: 0
- actual: b
expected: 0xff
7 changes: 7 additions & 0 deletions spec/ks/bits_signed_shift_b64_le.kst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
id: bits_signed_shift_b64_le
data: bits_signed_shift_b64_le.bin
asserts:
- actual: a
expected: 0
- actual: b
expected: 0xff
Binary file added src/bits_signed_shift_b32_le.bin
Binary file not shown.
Binary file added src/bits_signed_shift_b64_le.bin
Binary file not shown.

0 comments on commit b7e567f

Please sign in to comment.