From 0ad1f05e99c19c79acc7f5e8e18a94468af275ac Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Tue, 14 Dec 2021 12:48:22 +0100 Subject: [PATCH] mov: fix an exotic paletted MOV reading --- nihav-commonfmt/src/demuxers/mov.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/nihav-commonfmt/src/demuxers/mov.rs b/nihav-commonfmt/src/demuxers/mov.rs index 23781a9..aea8ecb 100644 --- a/nihav-commonfmt/src/demuxers/mov.rs +++ b/nihav-commonfmt/src/demuxers/mov.rs @@ -43,10 +43,11 @@ fn read_chunk_header(br: &mut ByteReader) -> DemuxerResult<(u32, u64)> { fn read_palette(br: &mut ByteReader, size: u64, pal: &mut [u8; 1024]) -> DemuxerResult { let _seed = br.read_u32be()?; - let _flags = br.read_u16be()?; + let flags = br.read_u16be()?; let palsize = (br.read_u16be()? as usize) + 1; validate!(palsize <= 256); - validate!((palsize as u64) * 8 + 8 == size); + validate!(flags == 0 || flags == 0x4000 || flags == 0x8000); + validate!((palsize as u64) * 8 + 8 <= size); for i in 0..palsize { let a = br.read_u16be()?; let r = br.read_u16be()?; @@ -55,7 +56,12 @@ fn read_palette(br: &mut ByteReader, size: u64, pal: &mut [u8; 1024]) -> Demuxer pal[i * 4] = (r >> 8) as u8; pal[i * 4 + 1] = (g >> 8) as u8; pal[i * 4 + 2] = (b >> 8) as u8; - pal[i * 4 + 3] = (a >> 8) as u8; + if flags == 0x8000 { + pal[i * 4 + 3] = (a >> 8) as u8; + } + } + if flags == 0x4000 { + br.read_skip(8)?; } Ok(size) } -- 2.39.5