question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

tarfile failure with long user ID

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
pts-dorianpulacommented, Feb 24, 2017

I did a bit of research and Android having busybox should handle GNU style tar files

I manually changed the generated build.py to use the GNU style format on line 181

- tf = tarfile.open(tfn, 'w:gz', format=tarfile.USTAR_FORMAT)
+ tf = tarfile.open(tfn, 'w:gz', format=tarfile.GNU_FORMAT)

and I was able to build and run the package using buildozer android_new debug deploy run.

0reactions
pushpendrecommented, May 9, 2021

Just wanted to say that this issue still exists. I installed buildozer a few days ago.

The suggestion above https://github.com/kivy/python-for-android/issues/1013#issuecomment-282204357

for f in $(fgrep -l USTAR_FORMAT $(find . -name build.py )); do 
  sed -i.bkp 's#USTAR_FORMAT#GNU_FORMAT#g' $f; done

was really useful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

tarfile — Read and write tar archive files ... - Python Docs
Names must not be longer than 100 characters, there is no user/group name information. Some archives have miscalculated header checksums in case of...
Read more >
Python tarfile fails - Stack Overflow
I am trying to write a script that tar a directory and scp's to a server which have lots of tar files. I...
Read more >
Does tar preserve permissions if user IDs change? - Server Fault
tar records permissions based on the UID and GID, not on the string associated with them. So if the UID on one server...
Read more >
tar without preserving user [duplicate] - Unix Stack Exchange
I'd like to compress some files for http distribution, but found that .tar.gz keeps the user name and user ID and there doesn't...
Read more >
tar: Exiting with failure status due to previous errors - Super User
You will get that message if, for any reason, tar can't add all of the specified files to the tar. One if the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found