Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binary data changed after encoding in azteccode #354

Open
renemeye opened this issue Mar 7, 2025 · 3 comments
Open

Binary data changed after encoding in azteccode #354

renemeye opened this issue Mar 7, 2025 · 3 comments

Comments

@renemeye
Copy link

renemeye commented Mar 7, 2025

Thank you for the great library!
We are encountering a very seldom but huge Issue where some binary data is wrongly encoded in the barcode.

Usually we are taking binary data as base64 and render it into an azteccode. Very seldomly those barcodes return the wrong data back after scanning. (Tested by multiple different barcode-scanners used in public transit. For my testing I use the QRbot App but the result is the same on every scanner.)
Putting the same data into Apple-Wallet PKPass works.

I was able to find two examples. In HEX the following happens (Only the part and a few bytes around the part that breaks)

IN: "6A 3E E8 AD F2 EF 17 99 3A 20 53 94 9F C3 1D 87"
OUT:"6A 3E E8 AD F2 EF 17 99 2F 94 9F C3 1D 89 46"

IN: "1D CE A4 2E 20 44 04 BD 19 7D A4 C9 18 1D 3E 74"
OUT:"1D CE A4 3A 20 04 BD 19 7D A4 C9 18 1D 3E 77"

I built you an example that directly takes the binary from hex. Tested on latest commit (ec9c2c8).

<!doctype html>
<html><head><title>bwip-js - JavaScript Barcode Generator</title>
<meta charset="utf-8" />
<script type="text/javascript" src="../dist/bwip-js.js"></script>

<canvas id="canvas" width=400 height=400 style="border:1px solid #fff"></canvas>

<script type="text/javascript">
  hex_data = "6A 3E E8 AD F2 EF 17 99 3A 20 53 94 9F C3 1D 87"

  // Working example -like most data-:
  // IN: "BC 64 0E 20 47 C8 6B 52 2D 81 76 A8 FA E4 7B B9"
  // OUT:"BC 64 0E 20 47 C8 6B 52 2D 81 76 A8 FA E4 7B B9"

  // Broken examples
  // IN: "6A 3E E8 AD F2 EF 17 99 3A 20 53 94 9F C3 1D 87"
  // OUT:"6A 3E E8 AD F2 EF 17 99 2F 94 9F C3 1D 89 46"
  //
  // IN: "1D CE A4 2E 20 44 04 BD 19 7D A4 C9 18 1D 3E 74"
  // OUT:"1D CE A4 3A 20 04 BD 19 7D A4 C9 18 1D 3E 77"


  function hexToByteString(hex) {
      let bytes = "";
      for (let c = 0; c < hex.length; c += 3)
          bytes += String.fromCharCode(parseInt(hex.substr(c, 2), 16));
      return bytes;
  }

  binary = hexToByteString(hex_data)

  canvas = bwipjs.toCanvas('canvas',{
    bcid: "azteccode",
    text: binary,
    binarytext: true,
    scale: 2,
    eclevel: 23,
  })
</script>

</div>
</body>
</html>

@metafloor
Copy link
Owner

metafloor commented Mar 7, 2025

Hi @terryburton, Can you take a look at the two "bad" examples? They are generating a rangecheck error in ghostscript.

Verified against BWIPP 2024-11-16. This is the dump from the first bad example:

Error: /rangecheck in --get--
Operand stack:
   cws   --nostringval--   24   29   62   --nostringval--   -52
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1990   1   3   %oparray_pop   1989   1   3   %oparray_pop   1977   1   3   %oparray_pop   1833   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   23   1   23   --nostringval--   %for_pos_int_continue   1   1   23   --nostringval--   %for_pos_int_continue   --nostringval--   --nostringval--
Dictionary stack:
   --dict:731/1123(ro)(G)--   --dict:0/20(G)--   --dict:75/200(L)--   --dict:112/160(L)--
Current allocation mode is local
GPL Ghostscript 9.50: Unrecoverable error, exit code 1

PostScript calls:

<6A 3E E8 AD F2 EF 17 99 3A 20 53 94 9F C3 1D 87> (eclevel=23) /azteccode
<1D CE A4 2E 20 44 04 BD 19 7D A4 C9 18 1D 3E 74> (eclevel=23) /azteccode

@terryburton
Copy link

Hi @terryburton, Can you take a look at the two "bad" examples?

Yes. It won't be immediate though as I'm recovering from flu.

Thanks for the triage.

@terryburton
Copy link

This ensures that the bitstream is properly truncated: bwipp/postscriptbarcode@d7c9cec

Please also let me know whether it resolves the original issue.

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

No branches or pull requests

3 participants