Skip to content

fix: decoding of binary data with null bytes - #108

Open
kateweaver wants to merge 1 commit into
NaturalHistoryMuseum:masterfrom
kateweaver:fix/binary-decoding-bug
Open

fix: decoding of binary data with null bytes#108
kateweaver wants to merge 1 commit into
NaturalHistoryMuseum:masterfrom
kateweaver:fix/binary-decoding-bug

Conversation

@kateweaver

@kateweaver kateweaver commented Jul 16, 2025

Copy link
Copy Markdown

Problem

Decoding binary data (e.g. Data Matrix codes encoded with Base256 that include null bytes) fails in pylibdmtx because the decode wrapper treats it as string-like and truncates the output at the first \x00. This prevents accurate round-tripping of binary payloads.

This behavior is not present in the underlying libdmtx C library, which handles null bytes correctly.

Evidence

Fix

  • fixes bug: decode() truncates Base256 binary data at null byte #109
  • fixes an issue where pylibdmtx.decode() trucates data at first null byte causing binary payloads (base256 encoded) to decode incorrectly
  • The underlying C library (libdmtx) supports null bytes correclty.
  • The Python wrapper used C strings as-si, which results in null-termination.
  • Replaces string_at(msg.contents.output)
  • Now uses string_at(msg.contents.output, msg.contents.outputIdx)
  • Tests added to verify null handling in both binary and ascii data.

Tests

  • Added a test with binary and ascii payload including null byte.
  • Confirmed failure before fix.
  • Confirmed all tests pass after fix.

Additional Notes

  - fixes and issue where pylibdmtx.decode() trucates data at first null
    byte causing binary payloads (base256 encoded) to decode incorrectly
  - The underlying C library (libdmtx) supports null bytes correclty.
  - The Python wrapper used C strings as-si, which results in
    null-termination.
  - Replaces string_at(msg.contents.output)
  - Now uses string_at(msg.contents.output, msg.contents.outputIdx)
  - Tests added to verify null handling in both binary and ascii data.
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.

bug: decode() truncates Base256 binary data at null byte

1 participant