mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-25 08:55:11 +01:00
std/xz: decode concatenated streams
This commit is contained in:
1 parent
5b62289c63
commit
22b4ff4842
7 files changed
+141
-13
No files matched your search
+45
-4
@@ -22,6 +22,7 @@ pub status "#bad checksum"
|
||||
pub status "#bad filter"
|
||||
pub status "#bad footer"
|
||||
pub status "#bad header"
|
||||
pub status "#bad header (concatenated stream)"
|
||||
pub status "#bad index"
|
||||
pub status "#bad padding"
|
||||
pub status "#truncated input"
|
||||
@@ -44,7 +45,8 @@ pub struct decoder? implements base.io_transformer(
|
||||
// 3: SHA-256.
|
||||
checksummer : base.u8[..= 3],
|
||||
|
||||
ignore_checksum : base.bool,
|
||||
ignore_checksum : base.bool,
|
||||
standalone_format : base.bool,
|
||||
|
||||
lzma_needs_reset : base.bool,
|
||||
|
||||
@@ -102,8 +104,14 @@ pub struct decoder? implements base.io_transformer(
|
||||
)
|
||||
|
||||
pub func decoder.get_quirk(key: base.u32) base.u64 {
|
||||
if (args.key == base.QUIRK_IGNORE_CHECKSUM) and this.ignore_checksum {
|
||||
return 1
|
||||
if args.key == base.QUIRK_IGNORE_CHECKSUM {
|
||||
if this.ignore_checksum {
|
||||
return 1
|
||||
}
|
||||
} else if args.key == QUIRK_DECODE_STANDALONE_CONCATENATED_STREAMS {
|
||||
if this.standalone_format {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
@@ -112,6 +120,9 @@ pub func decoder.set_quirk!(key: base.u32, value: base.u64) base.status {
|
||||
if args.key == base.QUIRK_IGNORE_CHECKSUM {
|
||||
this.ignore_checksum = args.value > 0
|
||||
return ok
|
||||
} else if args.key == QUIRK_DECODE_STANDALONE_CONCATENATED_STREAMS {
|
||||
this.standalone_format = args.value > 0
|
||||
return ok
|
||||
}
|
||||
return base."#unsupported option"
|
||||
}
|
||||
@@ -151,6 +162,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
var uncompressed_size : base.u64
|
||||
var hash : base.u32
|
||||
var c8 : base.u8
|
||||
var c32 : base.u32
|
||||
var footer_magic : base.u16
|
||||
|
||||
while.streams true {
|
||||
@@ -182,6 +194,7 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
}
|
||||
this.flags = (header_magic & 0xFFFF) as base.u16
|
||||
|
||||
this.num_actual_blocks = 0
|
||||
while.blocks true {
|
||||
if args.src.length() <= 0 {
|
||||
yield? base."$short read"
|
||||
@@ -431,7 +444,34 @@ pri func decoder.do_transform_io?(dst: base.io_writer, src: base.io_reader, work
|
||||
return "#bad footer"
|
||||
}
|
||||
|
||||
break.streams
|
||||
if not this.standalone_format {
|
||||
break.streams
|
||||
}
|
||||
|
||||
// Consume any Stream Padding.
|
||||
while.stream_padding true {
|
||||
while args.src.length() < 4,
|
||||
post args.src.length() >= 4,
|
||||
{
|
||||
if args.src.is_closed() {
|
||||
if args.src.length() == 0 {
|
||||
break.streams
|
||||
} else {
|
||||
return "#truncated input"
|
||||
}
|
||||
}
|
||||
yield? base."$short read"
|
||||
} endwhile
|
||||
|
||||
c32 = args.src.peek_u32le()
|
||||
if c32 == '\xFD\x37\x7A\x58'le {
|
||||
break.stream_padding
|
||||
} else if c32 <> 0 {
|
||||
return "#bad header (concatenated stream)"
|
||||
}
|
||||
args.src.skip_u32_fast!(actual: 4, worst_case: 4)
|
||||
} endwhile.stream_padding
|
||||
this.started_verify_index = false
|
||||
} endwhile.streams
|
||||
}
|
||||
|
||||
@@ -643,6 +683,7 @@ pri func decoder.verify_index?(src: base.io_reader) {
|
||||
return "#bad index"
|
||||
}
|
||||
|
||||
this.num_index_blocks = 0
|
||||
shift = 0
|
||||
while true {
|
||||
c8 = args.src.read_u8?()
|
||||
|
||||
Reference in new issue
Block a user