Skip to content

tarfile failure with long user ID #1013

Closed
@artwyman

Description

@artwyman

Note this is a follow-on from the same effort which produced #1012, but I think the bugs are independent. I switched to Python 3 and the CrystaxNDK in an attempt to avoid NDK build errors, and got far enough to run into this.

While the dist's build.py is building its tar archive, I get ValueError("overflow in number field"):

Traceback (most recent call last):
  File "/usr/local/bin/p4a", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.5/site-packages/pythonforandroid/toolchain.py", line 754, in main
    ToolchainCL()
  File "/usr/local/lib/python3.5/site-packages/pythonforandroid/toolchain.py", line 343, in __init__
    getattr(self, command_method_name)(unknown)
  File "/usr/local/lib/python3.5/site-packages/pythonforandroid/toolchain.py", line 94, in wrapper_func
    func(self, args)
  File "/usr/local/lib/python3.5/site-packages/pythonforandroid/toolchain.py", line 589, in apk
    build_args = build.parse_args(args)
  File "/Users/testuser/.python-for-android/dists/unnamed_dist_1/build.py", line 488, in parse_args
    make_package(args)
  File "/Users/testuser/.python-for-android/dists/unnamed_dist_1/build.py", line 248, in make_package
    make_tar('assets/private.mp3', tar_dirs, args.ignore_path)
  File "/Users/testuser/.python-for-android/dists/unnamed_dist_1/build.py", line 197, in make_tar
    tf.add(fn, afn)
  File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tarfile.py", line 1938, in add
    self.addfile(tarinfo, f)
  File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tarfile.py", line 1960, in addfile
    buf = tarinfo.tobuf(self.format, self.encoding, self.errors)
  File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tarfile.py", line 802, in tobuf
    return self.create_ustar_header(info, encoding, errors)
  File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tarfile.py", line 821, in create_ustar_header
    return self._create_header(info, USTAR_FORMAT, encoding, errors)
  File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tarfile.py", line 916, in _create_header
    itn(info.get("uid", 0), 8, format),
  File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tarfile.py", line 211, in itn
    raise ValueError("overflow in number field")
ValueError: overflow in number field

It seems the overflow is in the "uid" field, and I notice that my UID on my Mac (part of a corporate domain) is pretty high at 1730938684. Looking at the package in tarfile.py it seems this is a limitation of the USTAR format which the python-4-android builder is selecting specifically. The default GNU format can support much larger numbers, though I presume the unpacking code used in the Android package might not support it?

I was able to work around this problem by running as a different local user account, so long as that account owns both the .python-for-android directory and the source input directory.

Since UID information isn't relevant when unpacking on Android it would be nice to discard it and make this not matter, if using the GNU tar format isn't an option. It doesn't look like the tarfile package gives the ability to do this directly, but you could chmod all the files to root (in a temporary location) before compressing them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions