termux / termux-packages

A package build system for Termux.
https://termux.dev
Other
13.11k stars 3.01k forks source link

[Bug]: cksum in coreutils fails with write error #11912

Closed fancsali closed 2 years ago

fancsali commented 2 years ago

Problem description

Calling cksum from the coreutils package seems to try to call write() twice emitting the expected output but then also an error message and a non 0 return code.

What steps will reproduce the bug?

Pipe any file to cksum:

touch foo
$ cksum < foo
4294967295 0
cksum: write error: Bad address
$ echo $?
1

What is the expected behavior?

The call should only return the sum and the file size and no error message/code:

touch foo
$ cksum < foo
4294967295 0

Further information

Calling the busybox version of the tool works fine:

busybox cksum < foo
4294967295 0

Also, the version numbers of the packages in question:

$ apt list | egrep 'coreutils|busybox'

busybox/stable,now 1.35.0-2 arm [installed]
coreutils/stable,now 9.1 arm [installed]

System information

termux-info:

Termux Variables:
unsupported
Packages CPU architecture:
arm
Subscribed repositories:
# sources.list
deb https://packages.termux.dev/apt/termux-main stable main
Updatable packages:
All packages up to date
termux-tools version:
1.29.2
Android version:
9
Kernel build information:
Linux localhost 4.19.122-09121-gd58e3f311e19 #1 SMP PREEMPT Wed Aug 19 00:35:31 PDT 2020 armv7l Android
Device manufacturer:
Google
Device model:
ASUS Chromebook Flip C100PA
licy183 commented 2 years ago

I can reproduce it on arm/i686, but not on aarch64/x86_64.

fancsali commented 2 years ago

I can reproduce it on arm/i686, but not on aarch64/x86_64.

Had a look myself, and sounds about right.

Haven't had a chance to try it on architectures other than ARM, though.

xtkoba commented 2 years ago

I believe this has the same root cause as #9056 (which is in fact not resolved but just worked around), suspecting a bug in Gnulib.

fancsali commented 2 years ago

I believe this has the same root cause as #9056 (which is in fact not resolved but just worked around), suspecting a bug in Gnulib.

Not sure what that means in this context: so how do we mitigate this?

xtkoba commented 2 years ago

I think I have finally found the bug in Gnulib:

--- a/lib/stdio-impl.h
+++ b/lib/stdio-impl.h
@@ -68,8 +68,10 @@
 # elif defined __ANDROID__ /* Android */
 #  ifdef __LP64__
 #   define _gl_flags_file_t int
+#   define _gl_struct_file_off_t int64_t
 #  else
 #   define _gl_flags_file_t short
+#   define _gl_struct_file_off_t __kernel_off_t
 #  endif
   /* Up to this commit from 2015-10-12
      <https://android.googlesource.com/platform/bionic.git/+/f0141dfab10a4b332769d52fa76631a64741297a>
@@ -96,7 +98,7 @@
                          unsigned char _nbuf[1]; \
                          struct { unsigned char *_base; size_t _size; } _lb; \
                          int _blksize; \
-                         fpos_t _offset; \
+                         _gl_struct_file_off_t _offset; \
                          /* More fields, not relevant here.  */ \
                        } *) fp)
 # else
Grimler91 commented 2 years ago

@xtkoba thanks for investigating and fixing the core issue! Do you want to report it to the gnulib developers? Otherwise I can do it, would be nice to get the fix upstream