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

-1 on uint? "4294967295 is not a valid ZBarOrientation" #139

Open
purplesword opened this issue Jul 11, 2022 · 2 comments · May be fixed by #151
Open

-1 on uint? "4294967295 is not a valid ZBarOrientation" #139

purplesword opened this issue Jul 11, 2022 · 2 comments · May be fixed by #151

Comments

@purplesword
Copy link

Hi, on a few rare occasions I got ValueError: 4294967295 is not a valid ZBarOrientation on some images. I assume it was due to -1 assigned to uint and got stored as UINT_MAX?

Enviroment:

  • OS: Linux, Ubuntu 20.04
  • libzbar0: 0.23-1.3
  • pyzbar 0.1.9
  • python 3.9

Traceback:

ValueError                                Traceback (most recent call last)
/tmp/ipykernel_957744/3082549785.py in <module>
      1 from pyzbar import pyzbar
----> 2 decoded = pyzbar.decode(gray_image)
      3 decoded

~/.virtualenvs/py397/lib/python3.9/site-packages/pyzbar/pyzbar.py in decode(image, symbols)
    232                 raise PyZbarError('Unsupported image format')
    233             else:
--> 234                 results.extend(_decode_symbols(_symbols_for_image(img)))
    235 
    236     return results

~/.virtualenvs/py397/lib/python3.9/site-packages/pyzbar/pyzbar.py in _decode_symbols(symbols)
    125 
    126         if zbar_symbol_get_orientation:
--> 127             orientation = ZBarOrientation(zbar_symbol_get_orientation(symbol)).name
    128         else:
    129             orientation = None

/usr/local/lib/python3.9/enum.py in __call__(cls, value, names, module, qualname, type, start)
    382         """
    383         if names is None:  # simple value lookup
--> 384             return cls.__new__(cls, value)
    385         # otherwise, functional API: we're creating a new Enum type
    386         return cls._create_(

/usr/local/lib/python3.9/enum.py in __new__(cls, value)
    700                 ve_exc = ValueError("%r is not a valid %s" % (value, cls.__qualname__))
    701                 if result is None and exc is None:
--> 702                     raise ve_exc
    703                 elif exc is None:
    704                     exc = TypeError(

ValueError: 4294967295 is not a valid ZBarOrientation

Unfortunately I cannot share the original bug doc due to privacy. I will try if I can reproduce the error on some shareable anonymized image. But I guess it's some -1 treated as 4294967295?

@simon-staal
Copy link

This issue affects me as well, I've done a little more digging and I think I've found the problematic lines. The ZBarOrientation enum class specifies an UNKNOWN type as -1 here. However, when setting zbar_symbol_get_orientation, the c_uint type is passed here. Presumably if this was changed to c_int this would solve this issue?
Not sure if this library is maintained at all anymore, but providing this info just in case.

@infacc
Copy link

infacc commented Jul 28, 2023

Same issue ...

I concur with the analysis that it is caused by the ZBarOrientation UNKNOWN (-1) being interpreted as unsigned integer.

It seems the exception is thrown after the QR code has been decoded. Therefore, one can set a breakpoint at the line causing the exception:

orientation = ZBarOrientation(zbar_symbol_get_orientation(symbol)).name

and look at the data variable in a debugger. It should show the QR code data.

I also found a QR code online that causes this problem. The one on the bottom right here:

qr-code-error

@infacc infacc linked a pull request Aug 31, 2023 that will close this 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

Successfully merging a pull request may close this issue.

3 participants