Florian Festi 0a4ec8
diff --git a/scripts/rpm2cpio.sh b/scripts/rpm2cpio.sh
Florian Festi 0a4ec8
index 4531271cc..74aeed851 100755
Florian Festi 0a4ec8
--- a/scripts/rpm2cpio.sh
Florian Festi 0a4ec8
+++ b/scripts/rpm2cpio.sh
Florian Festi 0a4ec8
@@ -15,13 +15,23 @@ _dd() {
Florian Festi 0a4ec8
 }
Florian Festi 0a4ec8
 
Florian Festi 0a4ec8
 calcsize() {
Florian Festi 0a4ec8
+
Florian Festi 0a4ec8
+	case "$(_dd $1 bs=4 count=1 | tr -d '\0')" in
Florian Festi 0a4ec8
+		"$(printf '\216\255\350')"*) ;; # '\x8e\xad\xe8'
Florian Festi 0a4ec8
+		*) fatal "File doesn't look like rpm: $pkg" ;;
Florian Festi 0a4ec8
+	esac
Florian Festi 0a4ec8
+
Florian Festi 0a4ec8
 	offset=$(($1 + 8))
Florian Festi 0a4ec8
 
Florian Festi 0a4ec8
 	local i b b0 b1 b2 b3 b4 b5 b6 b7
Florian Festi 0a4ec8
 
Florian Festi 0a4ec8
 	i=0
Florian Festi 0a4ec8
 	while [ $i -lt 8 ]; do
Florian Festi 0a4ec8
-		b="$(_dd $(($offset + $i)) bs=1 count=1)"
Florian Festi 0a4ec8
+		# add . to not loose \n
Florian Festi 0a4ec8
+		# strip \0 as it gets dropped with warning otherwise
Florian Festi 0a4ec8
+		b="$(_dd $(($offset + $i)) bs=1 count=1 | tr -d '\0' ; echo .)"
Florian Festi 0a4ec8
+		b=${b%.}    # strip . again
Florian Festi 0a4ec8
+
Florian Festi 0a4ec8
 		[ -z "$b" ] &&
Florian Festi 0a4ec8
 			b="0" ||
Florian Festi 0a4ec8
 			b="$(exec printf '%u\n' "'$b")"
Florian Festi 0a4ec8
@@ -33,7 +43,7 @@ calcsize() {
Florian Festi 0a4ec8
 	offset=$(($offset + $rsize))
Florian Festi 0a4ec8
 }
Florian Festi 0a4ec8
 
Florian Festi 0a4ec8
-case "$(_dd 0 bs=8 count=1)" in
Florian Festi e3ce4e
+case "$(_dd 0 bs=4 count=1 | tr -d '\0')" in
Florian Festi 0a4ec8
 	"$(printf '\355\253\356\333')"*) ;; # '\xed\xab\xee\xdb'
Florian Festi 0a4ec8
 	*) fatal "File doesn't look like rpm: $pkg" ;;
Florian Festi 0a4ec8
 esac
Florian Festi 0a4ec8
@@ -44,11 +54,11 @@ sigsize=$rsize
Florian Festi 0a4ec8
 calcsize $(($offset + (8 - ($sigsize % 8)) % 8))
Florian Festi 0a4ec8
 hdrsize=$rsize
Florian Festi 0a4ec8
 
Florian Festi 0a4ec8
-case "$(_dd $offset bs=3 count=1)" in
Florian Festi 0a4ec8
-	"$(printf '\102\132')"*) _dd $offset | bunzip2 ;; # '\x42\x5a'
Florian Festi 0a4ec8
-	"$(printf '\037\213')"*) _dd $offset | gunzip  ;; # '\x1f\x8b'
Florian Festi 0a4ec8
-	"$(printf '\375\067')"*) _dd $offset | xzcat   ;; # '\xfd\x37'
Florian Festi 0a4ec8
-	"$(printf '\135\000')"*) _dd $offset | unlzma  ;; # '\x5d\x00'
Florian Festi 0a4ec8
-	"$(printf '\050\265')"*) _dd $offset | unzstd  ;; # '\x28\xb5'
Florian Festi 0a4ec8
-	*) fatal "Unrecognized rpm file: $pkg" ;;
Florian Festi 0a4ec8
+case "$(_dd $offset bs=2 count=1 | tr -d '\0')" in
Florian Festi 0a4ec8
+	"$(printf '\102\132')") _dd $offset | bunzip2 ;; # '\x42\x5a'
Florian Festi 0a4ec8
+	"$(printf '\037\213')") _dd $offset | gunzip  ;; # '\x1f\x8b'
Florian Festi 0a4ec8
+	"$(printf '\375\067')") _dd $offset | xzcat   ;; # '\xfd\x37'
Florian Festi 0a4ec8
+	"$(printf '\135')") _dd $offset | unlzma      ;; # '\x5d\x00'
Florian Festi 0a4ec8
+	"$(printf '\050\265')") _dd $offset | unzstd  ;; # '\x28\xb5'
Florian Festi 0a4ec8
+	*) fatal "Unrecognized payload compression format in rpm file: $pkg" ;;
Florian Festi 0a4ec8
 esac