-
Notifications
You must be signed in to change notification settings - Fork 187
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
Decoding binary QR codes produces incorrect output #55
Comments
Yes, I've noticed that too. I believe that martin@dogmeat ~ % diff -u <(cat test.bin|xxd -c 1 -p) <(cat decoded.bin|xxd -c 1 -p) | head -n 40
--- /proc/self/fd/13 2019-09-12 12:41:45.593341520 +0200
+++ /proc/self/fd/14 2019-09-12 12:41:45.589341484 +0200
@@ -1,182 +1,275 @@
6d
+c2
8d
3a
14
73
79
+c2
be
-ea
+c3
+aa
+c2
82
6e
+c2
8e
4c
+c2
80
-f1
+c3
+b1
4f
-c4
-f6
+c3
+84
+c3
+b6
24
-c8
-f0
+c3
+88
+c3
+b0 From https://www.fileformat.info/info/unicode/utf8.htm:
And all bytes in Also, when I open I originally had assumed that Seems like what we need would be a separate option |
Thanks for your insight! The binary data decoding code is in the case QR_MODE_BYTE: {
unsigned char *buf;
unsigned c;
int len;
len = qr_pack_buf_read(&qpb, LEN_BITS[len_bits_idx][2]);
if (len < 0)
return -1;
/*Check to see if there are enough bits left now, so we don't have to
in the decode loop.*/
if (qr_pack_buf_avail(&qpb) < len << 3)
return -1;
entry->payload.data.buf = buf = (unsigned char *) malloc(len * sizeof(*buf));
entry->payload.data.len = len;
while (len-- > 0) {
c = qr_pack_buf_read(&qpb, 8);
self_parity ^= c;
*buf++ = (unsigned char) c;
}
} break; It doesn't seem to be mangling the data at this stage. I'll keep looking for the source of the problem. |
Tracing the calls:
The iconv_t sjis_cd;
iconv_t utf8_cd;
iconv_t latin1_cd;
iconv_t big5_cd;
/*This is the encoding the standard says is the default.*/
latin1_cd = iconv_open("UTF-8", "ISO8859-1");
/*But this one is often used, as well.*/
sjis_cd = iconv_open("UTF-8", "SJIS");
/*This is a trivial conversion just to check validity without extra code.*/
utf8_cd = iconv_open("UTF-8", "UTF-8");
/* add support for big5 encoding. */
big5_cd = iconv_open("UTF-8", "BIG-5"); So it appears even binary QR codes are always treated as text. There's code to detect character encoding. Later it switches on the QR code mode: /* DONE: This handles a multi-byte sequence split between
multiple data blocks. */
case QR_MODE_BYTE:
case QR_MODE_KANJI: {
// copy byte to bytebuf
in = (char *) entry->payload.data.buf;
inleft = entry->payload.data.len;
memcpy(bytebuf_text + bytebuf_ntext, in, inleft * sizeof(*bytebuf_text));
bytebuf_ntext += inleft;
} break; |
If a QR code doesn't specify the text encoding of binary data through Extended Channel Interpretation, ZBar tries to guess the encoding. This unconditional character set conversion makes it impossible to recover other types of binary data stored in the QR code. The QR decoder now supports the ZBAR_CFG_RAW_BINARY config option. If set, it will output the bytes without converting them to text. This allows access to the actual bytes encoded in a binary QR code. Closes: mchehab#55 Thanks: Martin von Wittich <martin.von.wittich@iserv.eu> Signed-off-by: Matheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com>
If a QR code doesn't specify the text encoding of binary data through Extended Channel Interpretation, ZBar tries to guess the encoding. This unconditional character set conversion makes it impossible to recover other types of binary data stored in the QR code. The QR decoder now supports the ZBAR_CFG_BINARY configuration option. If set, it will output the bytes without converting them to text. This allows access to the actual bytes encoded in a binary QR code. Closes: mchehab#55 Thanks: Martin von Wittich <martin.von.wittich@iserv.eu> Signed-off-by: Matheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com>
If a QR code doesn't specify the text encoding of binary data through Extended Channel Interpretation, ZBar tries to guess the encoding. This unconditional character set conversion makes it impossible to recover other types of binary data stored in the QR code. The QR decoder now supports the ZBAR_CFG_BINARY configuration option. If set, it will output the bytes without converting them to text. This allows access to the actual bytes encoded in a binary QR code. Closes: mchehab#55 Thanks: Martin von Wittich <martin.von.wittich@iserv.eu> Signed-off-by: Matheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com>
If a QR code doesn't specify the text encoding of binary data through Extended Channel Interpretation, ZBar tries to guess the encoding. This unconditional character set conversion makes it impossible to recover other types of binary data stored in the QR code. The QR decoder now supports the ZBAR_CFG_BINARY configuration option. If set, it will output the bytes without converting them to text. This allows access to the actual bytes encoded in a binary QR code. Closes: mchehab#55 Thanks: Martin von Wittich <martin.von.wittich@iserv.eu> Signed-off-by: Matheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com>
For anyone stumbling across this from search engines, you need to add The man page was never updated to include that option so it's very easy to miss. |
That's true... I guess I forgot to update the manuals since I use the Arch Wiki so much. I edited the paperkey Arch Wiki article back in the day with instructions on how to use the binary decoding mode. It's the original use case I wanted this feature to enable. I also described the new options in the Anyone want to make a pull request? |
Decoding QR codes containing binary data with
zbar 0.23
produces incorrect output.I can reliably recover base64-encoded binary data encoded as alphanumeric and binary QR codes. However, binary data encoded directly in a binary QR code isn't decoded correctly by
zbar
.Here's a script that reproduces the issue:
I want to decode binary data that's been QR encoded and printed on paper. I verified that the problem exists when trying to decode scanned images as well as video captured with
zbarcam
.The text was updated successfully, but these errors were encountered: