michal-grzedzicki / rpms / rpm

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