From c1d277e78d1efc7bfdc5b54c85ce6092dbe212a9 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Sat, 12 Sep 2026 10:37:01 +0200 Subject: [PATCH] nihav_hlblocks/demux: implement skipping PE player in detect_tags() This usually comes in handy with the embedded Bink player. --- nihav-hlblocks/src/demux.rs | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/nihav-hlblocks/src/demux.rs b/nihav-hlblocks/src/demux.rs index 96f8eb4..4c95a58 100644 --- a/nihav-hlblocks/src/demux.rs +++ b/nihav-hlblocks/src/demux.rs @@ -506,6 +506,35 @@ impl<'a> NAOptionHandler for DemuxerObject<'a> { } } +fn check_pe(br: &mut dyn ByteIO) -> DecoderResult { + br.seek(SeekFrom::Start(0x3C))?; + let pe_off = br.read_u32le()?; + if pe_off < 0x40 { return Err(DecoderError::InvalidData); } + br.seek(SeekFrom::Start(pe_off.into()))?; + let tag = br.read_tag()?; + if &tag != b"PE\x00\x00" { return Err(DecoderError::InvalidData); } + br.read_u16le()?; + let nsections = usize::from(br.read_u16le()?); + if !(1..=255).contains(&nsections) { return Err(DecoderError::InvalidData); } + br.read_skip(12)?; + let optional_hdr_size = usize::from(br.read_u16le()?); + br.read_skip(optional_hdr_size + 2)?; + + let mut pe_size = 0; + for _ in 0..nsections { + br.read_skip(16)?; + let size = br.read_u32le()?; + let offs = br.read_u32le()?; + br.read_skip(16)?; + if size > 0 { + pe_size = pe_size.max(u64::from(offs) + u64::from(size)); + } + } + if pe_size == 0 { return Err(DecoderError::InvalidData); } + + Ok(pe_size) +} + /// Checks input for various metadata tags. /// /// Music files often have various metadata (e.g. title, artist, genre etc) associated with them but not always being a part of the file/stream format but rather a generic extension prepended or appended to the elementary stream. @@ -518,6 +547,15 @@ pub fn detect_tags(br: &mut dyn ByteIO, verbose: bool) -> (bool, u64, Option