vp9kf: VP9 tile size prefixes are BIG-endian
Browse files at this commitde9bde5d9b1006f045aaf9ae4c2bae7ac79fc236Parent: 82ba2652 changed files +24 -5
crates/ec-vp9/src/decode.rsmodified+3 -2
| @@ -209,7 +209,8 @@ impl Decoder { | ||
| 209 | 209 | let tile_rows = 1usize << hdr.tile_info.rows_log2; |
| 210 | 210 | |
| 211 | 211 | // Tile data: every tile except the overall last carries a |
| 212 | - // 32-bit LE size prefix (spec 6.4). | |
| 212 | + // 32-bit BIG-endian size prefix (spec 6.4; libvpx `get_tile_buffer` | |
| 213 | + // reads it with `mem_get_be32`, vp9_decodeframe.c:1688/1690). | |
| 213 | 214 | let mut data: &[u8] = tail; |
| 214 | 215 | let mut tiles: Vec<&[u8]> = Vec::with_capacity(tile_cols * tile_rows); |
| 215 | 216 | for tr in 0..tile_rows { |
| @@ -219,7 +220,7 @@ impl Decoder { | ||
| 219 | 220 | tiles.push(data); |
| 220 | 221 | } else { |
| 221 | 222 | ensure(data.len() >= 4, "truncated tile size")?; |
| 222 | - let sz = u32::from_le_bytes(data[..4].try_into().unwrap()) as usize; | |
| 223 | + let sz = u32::from_be_bytes(data[..4].try_into().unwrap()) as usize; | |
| 223 | 224 | data = &data[4..]; |
| 224 | 225 | ensure(data.len() >= sz, "truncated tile data")?; |
| 225 | 226 | tiles.push(&data[..sz]); |
crates/ec-vp9/tests/scratch_tiledbg.rsmodified+21 -3
| @@ -37,11 +37,29 @@ fn tile_dbg() { | ||
| 37 | 37 | tail.len(), |
| 38 | 38 | &tail[..16.min(tail.len())] |
| 39 | 39 | ); |
| 40 | + // Tile size prefixes are BIG-endian (libvpx `mem_get_be32`, | |
| 41 | + // vp9_decodeframe.c:1686) -- a LE read turns a 4-column | |
| 42 | + // 1080p prefix into ~5e8 and starves the walk. | |
| 40 | 43 | if tail.len() >= 4 { |
| 41 | - let sz = u32::from_le_bytes(tail[..4].try_into().unwrap()) as usize; | |
| 44 | + let be = u32::from_be_bytes(tail[..4].try_into().unwrap()) as usize; | |
| 45 | + let le = u32::from_le_bytes(tail[..4].try_into().unwrap()) as usize; | |
| 46 | + println!(" first tile size prefix be={be} le={le} (tail-4 = {})", tail.len() - 4); | |
| 47 | + // Walk the prefixes: each must fit, and the LAST tile is the | |
| 48 | + // remainder (`get_tile_buffer` size = data_end - data). | |
| 49 | + let n = 1usize << (hdr.tile_info.cols_log2 + hdr.tile_info.rows_log2); | |
| 50 | + let (mut pos, mut ok) = (0usize, true); | |
| 51 | + for _ in 0..n.saturating_sub(1) { | |
| 52 | + if pos + 4 > tail.len() { | |
| 53 | + ok = false; | |
| 54 | + break; | |
| 55 | + } | |
| 56 | + let sz = u32::from_be_bytes(tail[pos..pos + 4].try_into().unwrap()) as usize; | |
| 57 | + pos += 4 + sz; | |
| 58 | + ok &= pos <= tail.len(); | |
| 59 | + } | |
| 42 | 60 | println!( |
| 43 | - " first tile size prefix {sz} (tail-4 = {})", | |
| 44 | - tail.len() - 4 | |
| 61 | + " walk: {n} tiles, prefixes consume {pos} ok={ok}, last tile {}", | |
| 62 | + tail.len().saturating_sub(pos) | |
| 45 | 63 | ); |
| 46 | 64 | } |
| 47 | 65 | } |