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

Null bytes in binary data #199

Closed
eliashoo opened this issue Mar 22, 2021 · 9 comments
Closed

Null bytes in binary data #199

eliashoo opened this issue Mar 22, 2021 · 9 comments

Comments

@eliashoo
Copy link

Hi,

I'm generating Aztec symbol with following code:

const { writeFileSync } = require("fs")
const { toBuffer } = require("bwip-js")

const code = Buffer.from("924635a200029246", "hex")

void toBuffer({
	bcid: "azteccode",
	text: code.toString("latin1"),
	backgroundcolor: "ffffff"
}).then(img => {
	writeFileSync("out.png", img)
})

When decoding the generated symbol with https://demo.dynamsoft.com/barcode-reader, i noticed that bytes after 00 have changed to 00 bytes. The same symbol generated with zint is read correctly with above reader.

Should it be possible to encode null bytes with bwip-js?

@metafloor
Copy link
Owner

There does appear to be a bug here. At least I can confirm the symbol generated by BWIPP differs from bwip-js.

What are the byte codes you expect from reading the barcode?

For reference, the BWIPP generated barcode produces:

f9 e4 91 8d 68 80 00 a4 8f 80

@eliashoo
Copy link
Author

Im not sure if I understand correctly but im expecting to get the exact bytes encoded above. Actually the data that im trying to encode is much larger but the problem appears to related to handling of null bytes.

After debugging i noticed that the problem comes from line 528 in file \dist\node-bwipjs.js:

function $forall(o, cb) {
    if (o instanceof Uint8Array) {
        for (var i = 0, l = o.length; i < l; i++) {
            if (!o[i]) { // 0 is falsy
                 break;
            }
            $k[$j++] = o[i];
            if (cb && cb()) break;
        }
 // snip
}

Im not sure if this is needed and if it's not then the fix is to drop that if check.

@metafloor
Copy link
Owner

We may have competing bug fixes. That bit of code fixed a bug in datamatrix. I will do some tests this weekend to see if it can be sorted out.

@eliashoo
Copy link
Author

eliashoo commented Apr 6, 2021

Hi,

Any progress on this?

@metafloor
Copy link
Owner

Not much. I cannot get the symbol generated by bwip-js to match the one generated by BWIPP, so there is something in the emulation that is not correct. But I also cannot get the symbol generated by BWIPP to produce the correct result either, so that is a concern as well.

Please post an image of a valid aztec code using the example data you provided above.

@eliashoo
Copy link
Author

eliashoo commented Apr 7, 2021

That's weird.

With this input ^146^070^053^162^000^002^146^070 and this generator https://the-burtons.xyz/barcode-generator/ with option parse, I generated following image
bwipp-barcode
which decodes correctly to bytes 924635a200029246 with https://demo.dynamsoft.com/barcode-reader/ reader

After commenting out the problematic if-statement from $forall, bwipp-js generates matching code.

@metafloor
Copy link
Owner

Apparently, I have forgotten how my command line tools work. Wasn't actually testing the changes...

If the image generated by BWIPP matches what you expect, then I can move the change in. bwip-js now matches the image generated by BWIPP (it was the zxing decoder that was showing an odd/incorrect decode and causing confusion).

@eliashoo
Copy link
Author

eliashoo commented Apr 8, 2021

Yes that image matches what is expected.

metafloor added a commit that referenced this issue Apr 8, 2021
@metafloor
Copy link
Owner

The fix for this is in version 2.1.3, released yesterday.

jabibi pushed a commit to nodoo/bwip-js that referenced this issue Dec 26, 2022
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

2 participants