Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions build/build_bin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ set_up_environment() {
export KCONFIG_NOTIMESTAMP=1 # Busybox
}

check_tar_integer_limits() {
# Same include directories as libgnu. An incorrect limit must not be packaged.
TAR_DIR=$ROOT_PATH/../source/native/src/main/jni/external/tar
TAR_LIMITS_PROBE=$ROOT_PATH/tests/tar_integer_limits.c
TAR_LIMITS_OUT=$LOCAL_PATH/tar_integer_limits.o
echo "Checking tar integer limits ($TARGET_ARCH)"
$CC -c \
-I$TAR_DIR/tar-config \
-I$TAR_DIR/tar-gnu-embedded \
-I$TAR_DIR/tar/gnu \
-o $TAR_LIMITS_OUT \
$TAR_LIMITS_PROBE || exit 1
rm -f $TAR_LIMITS_OUT
}

build_zlib() {
# For zstd
if [ ! -f $LOCAL_PATH/zlib-$ZLIB_VERSION.tar.gz ]; then
Expand Down Expand Up @@ -277,6 +292,7 @@ build() {

package() {
# $1: type
check_tar_integer_limits
case "$1" in
built-in)
package_built_in
Expand Down
22 changes: 22 additions & 0 deletions build/tests/tar_integer_limits.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* Compile-time probe for the bundled tar integer limits.
Include path matches libgnu: tar-config, tar-gnu-embedded, tar/gnu. */

#include <config.h>
#include <limits.h>
#include <stddef.h>
#include <stdint.h>

_Static_assert(BITSIZEOF_SIZE_T == sizeof (size_t) * CHAR_BIT,
"BITSIZEOF_SIZE_T does not match size_t");
_Static_assert(BITSIZEOF_PTRDIFF_T == sizeof (ptrdiff_t) * CHAR_BIT,
"BITSIZEOF_PTRDIFF_T does not match ptrdiff_t");
_Static_assert(SIZE_MAX == (size_t) -1,
"SIZE_MAX does not match (size_t)-1");
_Static_assert(PTRDIFF_MAX
== (ptrdiff_t) ((((size_t) 1)
<< (sizeof (ptrdiff_t) * CHAR_BIT - 1))
- 1),
"PTRDIFF_MAX does not match the signed pointer-difference bound");
_Static_assert((size_t) PTRDIFF_MIN
== (((size_t) 1) << (sizeof (ptrdiff_t) * CHAR_BIT - 1)),
"PTRDIFF_MIN does not match the signed pointer-difference bound");
119 changes: 119 additions & 0 deletions build/tests/tar_roundtrip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/bin/sh
# Device-side tar/zstd round trip.
# Usage: tar_roundtrip.sh TAR ZSTD
#
# Archive, list, and extract a tiny tree (an empty file and an icon directory)
# directly and through zstd. Each pipeline stage is checked on its own so a
# downstream success cannot hide an upstream error. A truncated archive must
# fail tar -tf.

set -eu

if [ "$#" -ne 2 ]; then
echo "usage: tar_roundtrip.sh TAR ZSTD" >&2
exit 2
fi

TAR=$1
ZSTD=$2

if [ ! -f "$TAR" ] || [ ! -f "$ZSTD" ]; then
echo "tar and zstd must be file paths" >&2
exit 2
fi

"$TAR" --version >/dev/null
"$ZSTD" --version >/dev/null

work=${TMPDIR:-/tmp}/tar-roundtrip.$$
rm -rf "$work"
mkdir -p "$work"
trap 'rm -rf "$work"' EXIT INT HUP TERM

# $1 is the upstream command (a function). The remaining arguments are the
# downstream command. Neither status is ignored.
run_pipe() {
upstream=$1
shift
status_file=$work/pipe.status
rm -f "$status_file"
set +e
{
set +e
"$upstream"
echo $? > "$status_file"
} | "$@"
downstream_rc=$?
set -e
if [ ! -f "$status_file" ]; then
echo "pipeline failed: $upstream reported no status" >&2
exit 1
fi
upstream_rc=$(cat "$status_file")
if [ "$upstream_rc" -ne 0 ] || [ "$downstream_rc" -ne 0 ]; then
echo "pipeline failed: $upstream=$upstream_rc downstream=$downstream_rc" >&2
exit 1
fi
}

src=$work/src
mkdir -p "$src/icon/com.example"
: > "$src/empty"
printf 'icon-bytes' > "$src/icon/com.example/icon.png"

cmp_tree() {
from=$1
to=$2
(cd "$from" && find . | sort) > "$work/tree.from"
(cd "$to" && find . | sort) > "$work/tree.to"
cmp "$work/tree.from" "$work/tree.to"
while IFS= read -r rel; do
if [ -f "$from/$rel" ]; then
cmp "$from/$rel" "$to/$rel"
fi
done < "$work/tree.from"
}

echo "direct archive"
"$TAR" --totals -cpf "$work/direct.tar" -C "$src" .
"$TAR" -tf "$work/direct.tar" > "$work/direct.list"
grep -q 'empty' "$work/direct.list"
grep -q 'icon/com.example/icon.png' "$work/direct.list"
mkdir -p "$work/direct.out"
"$TAR" --totals -xmpf "$work/direct.tar" -C "$work/direct.out"
cmp_tree "$src" "$work/direct.out"

tar_to_stdout() {
"$TAR" --totals -cpf - -C "$src" .
}

echo "zstd archive"
run_pipe tar_to_stdout "$ZSTD" -c > "$work/archive.tar.zst"

zstd_decompress() {
"$ZSTD" -d -c "$work/archive.tar.zst"
}

echo "zstd list"
run_pipe zstd_decompress "$TAR" -tf - > "$work/zstd.list"
grep -q 'empty' "$work/zstd.list"
grep -q 'icon/com.example/icon.png' "$work/zstd.list"

echo "zstd extract"
mkdir -p "$work/zstd.out"
run_pipe zstd_decompress "$TAR" --totals -xmpf - -C "$work/zstd.out"
cmp_tree "$src" "$work/zstd.out"

echo "truncated archive"
dd if="$work/direct.tar" of="$work/trunc.tar" bs=128 count=1 2>/dev/null
set +e
"$TAR" -tf "$work/trunc.tar" >/dev/null 2>"$work/trunc.err"
trunc_rc=$?
set -e
if [ "$trunc_rc" -eq 0 ]; then
echo "truncated archive passed validation" >&2
exit 1
fi

echo "round trip ok"
exit 0
Binary file modified source/app/src/armeabi-v7a/assets/bin.zip
Binary file not shown.
Binary file modified source/app/src/x86/assets/bin.zip
Binary file not shown.
26 changes: 22 additions & 4 deletions source/native/src/main/jni/external/tar/tar-config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,24 @@
/* Define if building universal (internal helper macro) */
/* #undef AC_APPLE_UNIVERSAL_BUILD */

/* Define to the number of bits in type 'ptrdiff_t'. */
/* Define to the number of bits in type 'ptrdiff_t'.
Width follows the compiler target: 32-bit Android is ILP32. */
#if defined __SIZEOF_PTRDIFF_T__ && __SIZEOF_PTRDIFF_T__ == 4
#define BITSIZEOF_PTRDIFF_T 32
#else
#define BITSIZEOF_PTRDIFF_T 64
#endif

/* Define to the number of bits in type 'sig_atomic_t'. */
#define BITSIZEOF_SIG_ATOMIC_T 32

/* Define to the number of bits in type 'size_t'. */
/* Define to the number of bits in type 'size_t'.
Width follows the compiler target: 32-bit Android is ILP32. */
#if defined __SIZEOF_SIZE_T__ && __SIZEOF_SIZE_T__ == 4
#define BITSIZEOF_SIZE_T 32
#else
#define BITSIZEOF_SIZE_T 64
#endif

/* Define to the number of bits in type 'wchar_t'. */
#define BITSIZEOF_WCHAR_T 32
Expand Down Expand Up @@ -2212,8 +2222,12 @@
/* #undef PTHREAD_IN_USE_DETECTION_HARD */

/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
'ptrdiff_t'. */
'ptrdiff_t'. 32-bit Android ptrdiff_t is int; 64-bit is long. */
#if defined __SIZEOF_PTRDIFF_T__ && __SIZEOF_PTRDIFF_T__ == 4
#define PTRDIFF_T_SUFFIX
#else
#define PTRDIFF_T_SUFFIX l
#endif

/* Define to 1 if readlink fails to recognize a trailing slash. */
/* #undef READLINK_TRAILING_SLASH_BUG */
Expand Down Expand Up @@ -2282,8 +2296,12 @@
#endif

/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
'size_t'. */
'size_t'. 32-bit Android size_t is unsigned int; 64-bit is unsigned long. */
#if defined __SIZEOF_SIZE_T__ && __SIZEOF_SIZE_T__ == 4
#define SIZE_T_SUFFIX u
#else
#define SIZE_T_SUFFIX ul
#endif

/* If using the C implementation of alloca, define if you know the
direction of stack growth for your system; otherwise it will be
Expand Down
19 changes: 16 additions & 3 deletions source/native/src/main/jni/external/tar/tar-gnu-embedded/stdint.h
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,18 @@ typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t)
# define PTRDIFF_MAX _STDINT_MAX (1, 32, 0)
# endif
# else
# define PTRDIFF_MIN \
/* 32-bit Android ptrdiff_t is int. A 64-bit constant overflows that type. */
# if defined __SIZEOF_PTRDIFF_T__ && __SIZEOF_PTRDIFF_T__ == 4
# define PTRDIFF_MIN \
_STDINT_SIGNED_MIN (32, 0)
# define PTRDIFF_MAX \
_STDINT_MAX (1, 32, 0)
# else
# define PTRDIFF_MIN \
_STDINT_SIGNED_MIN (64, 0l)
# define PTRDIFF_MAX \
# define PTRDIFF_MAX \
_STDINT_MAX (1, 64, 0l)
# endif
# endif

/* sig_atomic_t limits */
Expand All @@ -570,7 +578,12 @@ typedef int _verify_intmax_size[sizeof (intmax_t) == sizeof (uintmax_t)
# define SIZE_MAX _STDINT_MAX (0, 32, 0ul)
# endif
# else
# define SIZE_MAX _STDINT_MAX (0, 64, 0ul)
/* 32-bit Android size_t is unsigned int, so the limit uses a 32-bit u suffix. */
# if defined __SIZEOF_SIZE_T__ && __SIZEOF_SIZE_T__ == 4
# define SIZE_MAX _STDINT_MAX (0, 32, 0u)
# else
# define SIZE_MAX _STDINT_MAX (0, 64, 0ul)
# endif
# endif

/* wchar_t limits */
Expand Down