bwipp / postscriptbarcode

Barcode Writer in Pure PostScript
https://bwipp.terryburton.co.uk
MIT License
462 stars 64 forks source link

Longitude validation (GS1 AI 4309) always fails #257

Closed elvijsm2 closed 9 months ago

elvijsm2 commented 9 months ago

It appears impossible to generate GS1 barcodes with the AI 4309 (Ship-to / Deliver-to GEO location) with linting enabled.

E.g., generating a databarexpanded barcode with the following content (00)123456789012345675(4309)09000000000000000000 (00)123456789012345675(4309)14220219500001282028 both fail with bwipp.GS1badLongitude AI 4309: Invalid value for longitude.

The problem is probably caused by 3600000000 not fitting in a 32-bit signed integer: cvi 3600000000 gt { pop /bwipp.GS1badLongitude (Invalid value for longitude) false exit } https://github.com/bwipp/postscriptbarcode/blob/e14a55de099bf71c81886ee8fe334d3e2d275929/src/gs1process.ps#L2833C100-L2833C100

terryburton commented 9 months ago

What implementation of the PS VM are you using?

What does it output when processing the following:

%!PS
/a == (0900000000) cvi ==
/b == 3600000000 ==
/c == (0900000000) cvi 3600000000 gt ==
elvijsm2 commented 9 months ago

I am on GPL Ghostscript 10.01.2. The output is

/a
900000000
/b
3600000000
/c
false

I encountered the error via treepoem (version 3.23.0) which packages its own barcode.ps. I now built bwipp myself and pointed treepoem to use the barcode.ps under ./build/monolithic_package and ./build/monolithic. With the former, I get the same error, whereas with the latter it works fine. The generated barcode image can also be properly decoded.

terryburton commented 9 months ago

I now built bwipp myself and pointed treepoem to use the barcode.ps under ./build/monolithic_package and ./build/monolithic. With the former, I get the same error, whereas with the latter it works fine. The generated barcode image can also be properly decoded.

That appears to be a bug in the packaged resource encoder (which I don't maintain). This replaces strings with more efficient binarised tokens. Seems like it's getting the maths wrong for large integers.

If you replace the code in the source .ps file as follows, then rebuild the monolithic_package, does it work?

- cvi 3600000000 gt { pop /bwipp.GS1badLongitude (Invalid value for longitude) false exit } if
+ cvi (3600000000) cvi gt { pop /bwipp.GS1badLongitude (Invalid value for longitude) false exit } if
elvijsm2 commented 9 months ago

Yes, if I change src/gs1process.ps as suggested and then make again, using the resulting ./build/monolithic_package/barcode.ps gives the same output as with ./build/monolithic/barcode.ps.

terryburton commented 9 months ago

The packages in release 2023-12-07 now include the workaround.

elvijsm2 commented 9 months ago

Tested on the latest master 4e130138bddab39193290416841b477e50c9dde8, the generation works fine now 👍

terryburton commented 9 months ago

Thanks.