xz compression detection: avoid the need to seek
function old new delta
unpack_unxz 12 67 +55
unpack_xz_stream 2357 2373 +16
xmalloc_read 197 199 +2
setup_unzip_on_fd 118 99 -19
rpm2cpio_main 222 203 -19
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/2 up/down: 73/-38) Total: 35 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
diff --git a/archival/bbunzip.c b/archival/bbunzip.c
index b243afb..832a7bb 100644
--- a/archival/bbunzip.c
+++ b/archival/bbunzip.c
@@ -373,6 +373,15 @@
static
IF_DESKTOP(long long) int FAST_FUNC unpack_unxz(unpack_info_t *info UNUSED_PARAM)
{
+ struct {
+ uint32_t v1;
+ uint16_t v2;
+ } magic;
+ xread(STDIN_FILENO, &magic, 6);
+ if (magic.v1 != XZ_MAGIC1a || magic.v2 != XZ_MAGIC2a) {
+ bb_error_msg("invalid magic");
+ return -1;
+ }
return unpack_xz_stream(STDIN_FILENO, STDOUT_FILENO);
}
int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;