summaryrefslogtreecommitdiffstats
path: root/debian/tests/oversized-chunks
blob: b610c42e05ac537b9596782b74be0705777f4b73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
#
# This test was written in response to http://bugs.debian.org/785075 to
# attempt to automatically catch when/if it happens again.
# It seems something in the build toolchain is sometimes producing lots
# of embedded zeroes in the executables.
# For example in util-linux 2.26.2-2 the /sbin/fstrim was over 2MB in size
# instead of normal ~ 40kB.
#
# Copyright (c) 2015, Andreas Henriksson <andreas@fatal.se>
set -e
set -u
#set -x

PACKAGES="util-linux bsdutils mount"
# 80k should be large enough to not trigger false positives. Bump this
# up if needed. Andreas committed this with 10k, and it was fine until
# July 2022 on arm* architectures. Suddenly an empty chunk of 56k size
# appeared in /bin/dmesg. In the interest of having util-linux migrate
# to testing, Chris has increased this limit and mailed the arm porters.
CHUNKSIZELIMIT="80000"

CURRENT=""
LAST=""
RET=0


for FILE in $(dpkg -L $PACKAGES | egrep '/s?bin/') ; do

if [ ! -e "$FILE" ]; then
	#echo "E: target file '$FILE' not found." >&2
	exit 1
fi

function chunk_size
{
	#echo "DEBUG: start => $1, stop => $2" >&2
	SIZE=$(echo ibase=16 \; ${2^^} - ${1^^} | bc)
	#echo "I: Calculated chunk size $SIZE ($2 - $1)" >&2
	echo $SIZE
}

hd $FILE | grep -C1 '^\*' | while read -a CURRENT
do
	if [ "${CURRENT[0]}" = "--" ]; then
		#echo "I: Skipping separator" >&2
		continue
	fi

	if [ "${CURRENT[0]}" = "*" ]; then
		#echo "I: Found chunk indicator." >&2
		START="$LAST"
	fi

	if [ "$LAST" = "*" ]; then
		#echo "I: Both start and stop should now be located." >&2
		STOP="${CURRENT[0]}"
		CHUNKSIZE=$(chunk_size "$START" "$STOP")
		echo "I: file $FILE has empty chunk starting at $START sized $CHUNKSIZE"
		if [ "$CHUNKSIZE" -gt "$CHUNKSIZELIMIT" ]; then
			echo "E: oversized chunk found in $FILE !"
			((RET++))
		fi
	fi

	#echo "I: Yet another line processed." >&2
	LAST="${CURRENT[0]}"

done

done

exit $RET