justusjonas74 / uic-918-3

Package for decoding and parsing barcodes according to UIC-918.3 specification, which are used commonly on public transport online tickets.
MIT License
39 stars 3 forks source link

Error: incorrect header check #6

Closed AdriDevelopsThings closed 8 months ago

AdriDevelopsThings commented 2 years ago

Hey,

I want to check my ticket (Deutsche Bahn) with this npm module. My code is:

import uic from 'uic-918-3'

const image = 'barcode.png'

uic.readBarcode(image).then((ticket) => {
    console.log(ticket)
})

But I get the following error:

node:internal/process/promises:246
          triggerUncaughtException(err, true /* fromPromise */);
          ^

Error: incorrect header check
    at Zlib.zlibOnError [as onerror] (node:zlib:190:17)
    at processChunkSync (node:zlib:456:12)
    at zlibBufferSync (node:zlib:178:12)
    at Object.syncBufferWrapper [as unzipSync] (node:zlib:791:14)
    at getTicketDataUncompressed (C:\Users\AdriDoesThings\Desktop\Projects\javascriptplayground\node_modules\uic-918-3\lib\barcode-data.js:30:17)
    at module.exports (C:\Users\AdriDoesThings\Desktop\Projects\javascriptplayground\node_modules\uic-918-3\lib\barcode-data.js:79:36)
    at interpretBarcodeFn (C:\Users\AdriDoesThings\Desktop\Projects\javascriptplayground\node_modules\uic-918-3\index.js:22:62) {
  errno: -3,
  code: 'Z_DATA_ERROR'
}
error 

Can somebody help me?

justusjonas74 commented 2 years ago

Hey, could you provide the image? I would like to check, what‘s happening…

Am 16.01.2022 um 19:06 schrieb AdriDevelopsThings @.***>:

 Hey,

I want to check my ticket (Deutsche Bahn) with this npm module. My code is:

import uic from 'uic-918-3'

const image = 'barcode.png'

uic.readBarcode(image).then((ticket) => { console.log(ticket) }) But I get the following error:

node:internal/process/promises:246 triggerUncaughtException(err, true / fromPromise /); ^

Error: incorrect header check at Zlib.zlibOnError [as onerror] (node:zlib:190:17) at processChunkSync (node:zlib:456:12) at zlibBufferSync (node:zlib:178:12) at Object.syncBufferWrapper [as unzipSync] (node:zlib:791:14) at getTicketDataUncompressed (C:\Users\AdriDoesThings\Desktop\Projects\javascriptplayground\node_modules\uic-918-3\lib\barcode-data.js:30:17) at module.exports (C:\Users\AdriDoesThings\Desktop\Projects\javascriptplayground\node_modules\uic-918-3\lib\barcode-data.js:79:36) at interpretBarcodeFn (C:\Users\AdriDoesThings\Desktop\Projects\javascriptplayground\node_modules\uic-918-3\index.js:22:62) { errno: -3, code: 'Z_DATA_ERROR' } error Can somebody help me?

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you are subscribed to this thread.

AdriDevelopsThings commented 2 years ago

Ticket

This is an official example ticket by deutsche bahn (https://www.bahn.de/angebot/regio/barcode)

justusjonas74 commented 2 years ago

It's a bug while reading the barcode. But I currently don't know how to fix it. Do you have a possibilty to get the binary data from the barcode? If so, you could use that data also.

import uic from 'uic-918-3'

const binaryData = Buffer.from('2355543031303038303030303037302C02146B646F806C2CBC1F16977166E626C3A251C30B5602144917F4E606DFA8150EB2FA4C174378972623E4740000000030333233789C6D90CD4EC24010C78B07F5E2C5534F86C48350539CD98F523C9014BA056285C40AE1661A056C2484B495A8275FC877F1017C1867900307770FFBDFDFFEE76367FCD037410808A025800F919A7AD3C095D6DE124D04411BA5D2109AD0B0B1138304891A04A204147CAABF532BBFA93CA5B5855E029C1B5AD172F6B6CE6759414010404142B20848B4486874C1858453700C0945422464A42A80789316C56C79D9CDCA77421EE789F274F5327FCDCBDA6D9AADEABB374115154E06C175B5371EDE3BB58EE9387D73973851E8F44C3CBCEA8E4CECC4A338767A833A05C86D438FCF79362FAB715A94C43CAECE6D0A9F5F999EEF2C097D9C7B44D9006CF09789882D517B84BA06C59C3467A320CDA39B8C79267ED37AA2E1560E2EBE6A73BB3CFAB6376DD7AAB41B36CF9CE1F1CFE189BDF938FBA4CBE23FC762E738CD7E01B9E06A43','hex') 

const ticket = uic.interpretBarcode(binaryData)
console.dir(ticket, { depth: null }); 
AdriDevelopsThings commented 2 years ago

I grab the data from https://github.com/rumpeltux/onlineticket and put it in the script and the same error happend.

This was my script:

import uic from 'uic-918-3'

const binaryData = Buffer.from('2355543031303038303030303037302c02146b646fc2806c2cc2bc1f16c2977166c3a626c383c2a251c3830b5602144917c3b4c3a606c39fc2a8150ec2b2c3ba4c174378c2972623c3a474000000003033323378c29c6dc290c38d4ec3824010c387c28b07c3b5c3a2c385534fc286c384c2835053c29cc399c28f523cc29014c2ba0562c285c3840ac3a1661a056c24c284c2b4c295c2a8275fc38877c3b1017c1867c2900307770fc3bbc39fc39fc3bec3a76367c3bcc39037410808c2a025c2800fc291c29a7ac393c380c295c396c39e124d04411bc2a5c39210c29ac390c2b0c2b113c28304c2891a04c2a204147cc2aac2bf532bc2bfc2a93cc2a5c2b5c2855e02c29c1b5ac39172c3b6c2b6c38e6759414010404142c2b20848c2b4486874c381c285c28453700c0945422464c2a42ac28078c29316c3856c79c399c38dc38a77421ec3a7c289c3b274c3b5327fc38dc38bc39a6dc29ac2adc3aac2bb374115154e06c38175c2b5371ec39e3bc2b5c28ec3a9387d73c2973851c3a8c3b44c3cc2bcc3aac28e4cc3acc384c2a338767ac2833a05c3886d43c28fc38f79362fc2ab715ac294c3843cc2aec38e6d0ac29f5fc299c29ec3af2c097dc29c7b44c399006cc3b0c297c289c2882d517bc284c2ba06c385c29c3467c2a320c38dc2a3c29bc28c79267ec3937ac2a2c3a1560e2ec2be6a73c2bb3cc3bac2b6376dc397c2aac2b41b36c38fc29cc3a1c3b1c38fc3a1c289c2bdc3b938c3bbc2a4c38bc3a23fc38762c3a738c38d7e01c2b9c3a06a430a','hex') 

const ticket = uic.interpretBarcode(binaryData)
console.dir(ticket, { depth: null }); 

onlineticket could read the ticket from this hex data.

AdriDevelopsThings commented 2 years ago

Okay: With the zxing fix of the hex it works. But when I supply the path to the image I get the error Error: incorrect header check. The Problem doesn't seem to be zxing because I saw that you have a fix for that.

justusjonas74 commented 2 years ago

It seems to be an issue on Windows machines only. I‘ve tested your ticket on Mac and everything is fine.

Am 17.01.2022 um 20:28 schrieb AdriDevelopsThings @.***>:

 Okay: With the zxing fix of the hex it works. But when I supply the path to the image I get the error Error: incorrect header check. The Problem doesn't seem to be zxing because I saw that you have a fix for that.

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.

AdriDevelopsThings commented 2 years ago

I tried it on my MacBook, and it works there. I can confirm that the problem is a windows only problem.

rena2019 commented 2 years ago

Windows machine only issue? I tried it with Linux:

myalpine:~# node ./uic918.js zlib.js:439 throw error; ^

Error: incorrect header check at Zlib.zlibOnError [as onerror] (zlib.js:182:17) at processChunkSync (zlib.js:431:12) at zlibBufferSync (zlib.js:168:12) at Object.syncBufferWrapper [as unzipSync] (zlib.js:766:14) at getTicketDataUncompressed (/root/node_modules/uic-918-3/lib/barcode-data.js:30:17) at Object.module.exports [as interpretBarcode] (/root/node_modules/uic-918-3/lib/barcode-data.js:79:36) at Object. (/root/uic918.js:5:20) at Module._compile (internal/modules/cjs/loader.js:999:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) at Module.load (internal/modules/cjs/loader.js:863:32) { errno: -3, code: 'Z_DATA_ERROR' } myalpine:~# uname -a Linux myalpine 5.4.143-0-virt #1-Alpine SMP Mon, 30 Aug 2021 10:31:41 UTC x86_64 Linux

jkampich1411 commented 2 years ago

Any updates on this?

zajiclib commented 1 year ago
zlib.js:182
  const error = new Error(message);
                ^

Error: incorrect header check
    at Zlib.zlibOnError [as onerror] (zlib.js:182:17)
    at processChunkSync (zlib.js:431:12)
    at zlibBufferSync (zlib.js:168:12)
    at Object.syncBufferWrapper [as unzipSync] (zlib.js:766:14)
    at getTicketDataUncompressed (/home/lzajicek/Dokumente/uic/node_modules/uic-918-3/lib/barcode-data.js:30:17)
    at Object.module.exports [as interpretBarcode] (/home/lzajicek/Dokumente/uic/node_modules/uic-918-3/lib/barcode-data.js:79:36)
    at file:///home/lzajicek/Dokumente/uic/uic_test.js:25:20
    at ModuleJob.run (internal/modules/esm/module_job.js:145:37)
    at async Loader.import (internal/modules/esm/loader.js:182:24)
    at async Object.loadESM (internal/process/esm_loader.js:68:5) {
  errno: -3,
  code: 'Z_DATA_ERROR'
}

Confirming that it is not only Windows machine issue. Any update on this at all? Or this thread is dead?

However this happened with different ticket.


const binaryData = Buffer.from('23555430323130383054543030321726bdaa1394001e0bd3d31d479a40e6bb4a71d78fe2435c0ce316bbe2222728264478d1a1d7157db4fcc91164fb42dbcb9ffe2a021ca277befcf818b1d7be9030323230789c0b8d77f3718d3034363034354ddac4d0f690f76093678ba8204723ab5c8b696ad6d58cab690bb81a18389aeedc39c436ebd065461697eb768c0c4a266539198eb916663e162b94132f9e8e938b355a7c61c6ed0b33148aca641f4f2e16d69e6c1925edbdf844569eece3626967ed42306fd7666fce8b8c0f3b1b0f367e749a1894c459a5545518c4e9c1c220c3d0ba809391415572e3d487074f4e5d7ac6c0c0c2202cd4c010489b33800023933ee7ceb21925ec1766943998303038984a808441821c77d87867945509cb0039e5d85494c354b002001e67526f','hex') 

const ticket = uic.interpretBarcode(binaryData)
console.dir(ticket, { depth: null }); ```
arnebr commented 8 months ago

Hi everyone, I found a solution for the error. The problem comes that the library implements the version 1.0.0 of the uic standard, but the version 2.0.0, which is used by most of the railway companies has a different header length and so the decompression needs to start somewhere different. You can spot the answer here: UnionInternationalCheminsdeFer/UIC-barcode#73

Have provided a fix in #14. But basically in pseudocode, you need to check:

if(header.mt_version==01){
use signature length 50 for signature
}else{
use signature length 64 for signature }