Skip to content

Commit

Permalink
Correctly handle cases where detected data contains null-bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaan Tallinn committed Apr 25, 2020
1 parent 833b375 commit 62401e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 5 additions & 2 deletions pyzbar/pyzbar.py
Expand Up @@ -9,7 +9,7 @@
zbar_image_scanner_create, zbar_image_scanner_destroy,
zbar_image_create, zbar_image_destroy, zbar_image_set_format,
zbar_image_set_size, zbar_image_set_data, zbar_scan_image,
zbar_image_first_symbol, zbar_symbol_get_data,
zbar_image_first_symbol, zbar_symbol_get_data_length, zbar_symbol_get_data,
zbar_symbol_get_loc_size, zbar_symbol_get_loc_x, zbar_symbol_get_loc_y,
zbar_symbol_next, ZBarConfig, ZBarSymbol, EXTERNAL_DEPENDENCIES
)
Expand Down Expand Up @@ -97,7 +97,10 @@ def _decode_symbols(symbols):
Decoded: decoded symbol
"""
for symbol in symbols:
data = string_at(zbar_symbol_get_data(symbol))
data = string_at(
zbar_symbol_get_data(symbol),
zbar_symbol_get_data_length(symbol)
)
# The 'type' int in a value in the ZBarSymbol enumeration
symbol_type = ZBarSymbol(symbol.contents.type).name
polygon = convex_hull(
Expand Down
7 changes: 4 additions & 3 deletions pyzbar/wrapper.py
Expand Up @@ -15,8 +15,9 @@
'zbar_image_scanner_create', 'zbar_image_scanner_destroy',
'zbar_image_scanner_set_config', 'zbar_image_set_data',
'zbar_image_set_format', 'zbar_image_set_size', 'zbar_scan_image',
'zbar_symbol_get_data', 'zbar_symbol_get_loc_size',
'zbar_symbol_get_loc_x', 'zbar_symbol_get_loc_y', 'zbar_symbol_next'
'zbar_symbol_get_data_length', 'zbar_symbol_get_data',
'zbar_symbol_get_loc_size', 'zbar_symbol_get_loc_x',
'zbar_symbol_get_loc_y', 'zbar_symbol_next'
]

# Globals populated in load_libzbar
Expand Down Expand Up @@ -234,7 +235,7 @@ def zbar_function(fname, restype, *args):

zbar_symbol_get_data = zbar_function(
'zbar_symbol_get_data',
c_char_p,
c_ubyte_p,
POINTER(zbar_symbol)
)

Expand Down

0 comments on commit 62401e8

Please sign in to comment.