xolox / python-deb-pkg-tools

Debian packaging tools
https://pypi.python.org/pypi/deb-pkg-tools
MIT License
42 stars 11 forks source link

Ensure device nodes can be parsed from contents #22

Closed MrTam closed 4 years ago

MrTam commented 4 years ago

Hey @xolox !

Came across an issue parsing the contents of a package using deb_pkg_tools today. Packages which reference device nodes (granted odd and obscure but do exist), populate the size field of these nodes as their block device IDs in ls and dpkg-deb -c:

$ dpkg-deb -c libxenomai1_2.6.4-1_1jessie_1da_i386.deb
crw-r--r-- root/root     150,0 2015-12-07 16:40 ./dev/rtp0
crw-r--r-- root/root     150,1 2015-12-07 16:40 ./dev/rtp1
crw-r--r-- root/root     150,2 2015-12-07 16:40 ./dev/rtp2
crw-r--r-- root/root     150,3 2015-12-07 16:40 ./dev/rtp3
crw-r--r-- root/root     150,4 2015-12-07 16:40 ./dev/rtp4                                 

This causes a ValueError when attempting to coerce the parsed size value as an integer within the inspect_package_contents function:

>>> p.inspect_package_contents("libxenomai1_2.6.4-1_1jessie_1da_i386.deb")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/tgibson/cloudsmith/.venv/lib/python3.8/site-packages/deb_pkg_tools/package.py", line 719, in inspect_package_contents
    size = int(fields[2])
ValueError: invalid literal for int() with base 10: '150,0'

Change below simply wraps the assignment and cast in a try/catch and ensures the size is reported zero. It's not quite correct that its zero sized, but it does allow for the cast, and ensures the types remain the same within the ArchiveEntry tuple for other users.

Let me know if you need anything else here.

Thanks! Tom

coveralls commented 4 years ago

Coverage Status

Coverage increased (+0.08%) to 91.694% when pulling 6369bfe81fe716be2e2b24ca917608dc7bcdc27c on cloudsmith-io:bugfix-device-node-size into 437b6a7748ecc191ca87e8247bca71d625737fbf on xolox:master.

coveralls commented 4 years ago

Coverage Status

Coverage increased (+0.08%) to 91.694% when pulling 6369bfe81fe716be2e2b24ca917608dc7bcdc27c on cloudsmith-io:bugfix-device-node-size into 437b6a7748ecc191ca87e8247bca71d625737fbf on xolox:master.

xolox commented 4 years ago

Hi Tom and thanks for the contribution! I've merged your pull request and then decided to enhance inspect_package_contents() to properly parse device file type information (because throwing the information away while parsing didn't feel right). These changes are part of deb-pkg-tools 8.1 which was just released.