From 60b7dbfc8f67f39a300b052b19b48a2656b0bbce Mon Sep 17 00:00:00 2001 From: The412Banner <205237651+The412Banner@users.noreply.github.com> Date: Thu, 3 Dec 2026 12:31:31 +0000 Subject: [PATCH] fix(epic): download chunks of version 22+ manifests from their ChunksV5 paths --- app/src/main/rust/stores/src/epic/manifest.rs | 82 ++++++++++++++++++- 1 file changed, 80 insertions(+), 2 deletions(-) diff --git a/app/src/main/rust/stores/src/epic/manifest.rs b/app/src/main/rust/stores/src/epic/manifest.rs index 98d31f3d9d..10ef43a61a 100644 --- a/app/src/main/rust/stores/src/epic/manifest.rs +++ b/app/src/main/rust/stores/src/epic/manifest.rs @@ -1,10 +1,13 @@ use std::collections::HashMap; use std::io::Read; +use crate::amazon::net::base64url; + pub const BINARY_MAGIC: u32 = 0x44BE_C00C; pub const DEFAULT_WINDOW: u32 = 1024 * 1024; const MIN_HEADER: usize = 41; const MAX_BODY: usize = 1 << 30; +const SECRET_VERSION: i64 = 22; pub type Guid = [u32; 4]; pub type Sha1 = [u8; 20]; @@ -38,6 +41,7 @@ pub struct ChunkInfo { pub window: u32, pub window_exact: bool, pub cdn_size: u64, + pub secret: Guid, } #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -87,6 +91,17 @@ impl Manifest { } pub fn chunk_path(&self, chunk: &ChunkInfo) -> String { + if self.version >= SECRET_VERSION { + let secret = if chunk.secret == [0; 4] { "plain".to_string() } else { guid_b64(&chunk.secret) }; + return format!( + "{}/{}/{:02}/{}_{}.chunk", + self.chunk_folder(), + secret, + chunk.group, + base64url(&chunk.rolling_hash.to_le_bytes()), + guid_b64(&chunk.guid) + ); + } format!( "{}/{:02}/{:016X}_{}.chunk", self.chunk_folder(), @@ -97,8 +112,14 @@ impl Manifest { } } +fn guid_b64(guid: &Guid) -> String { + let bytes: Vec = guid.iter().flat_map(|v| v.to_le_bytes()).collect(); + base64url(&bytes) +} + pub fn chunk_folder(variant: Variant, version: i64) -> &'static str { match version { + v if v >= SECRET_VERSION => "ChunksV5", v if v >= 15 => "ChunksV4", v if v >= 6 => "ChunksV3", v if v >= 3 => "ChunksV2", @@ -271,7 +292,7 @@ fn parse_binary(bytes: &[u8]) -> Result { let (meta, after_meta) = section(body, 0)?; let meta = read_meta(meta); let (chunk_list, after_chunks) = section(body, after_meta)?; - let (chunks, chunk_index) = read_chunk_list(chunk_list)?; + let (chunks, chunk_index) = read_chunk_list(chunk_list, version)?; let (file_list, _after_files) = section(body, after_chunks)?; let files = read_file_list(file_list)?; @@ -325,7 +346,7 @@ fn read_meta(data: &[u8]) -> Meta { meta } -fn read_chunk_list(data: &[u8]) -> Result<(Vec, HashMap), String> { +fn read_chunk_list(data: &[u8], version: i64) -> Result<(Vec, HashMap), String> { let mut r = Reader::new(data); r.u8()?; let count = r.count(16 + 8 + 20 + 1 + 4 + 8)?; @@ -353,6 +374,12 @@ fn read_chunk_list(data: &[u8]) -> Result<(Vec, HashMap) for _ in 0..count { sizes.push(r.i64()?); } + let mut secrets = vec![[0u32; 4]; count]; + if version >= SECRET_VERSION { + for secret in secrets.iter_mut() { + *secret = r.guid()?; + } + } let mut chunks: Vec = Vec::with_capacity(count); let mut index: HashMap = HashMap::with_capacity(count); for i in 0..count { @@ -365,6 +392,7 @@ fn read_chunk_list(data: &[u8]) -> Result<(Vec, HashMap) window: if window > 0 { window as u32 } else { DEFAULT_WINDOW }, window_exact: window > 0, cdn_size: sizes[i].max(0) as u64, + secret: secrets[i], }; match index.get(&info.guid) { Some(&at) => chunks[at] = info, @@ -500,6 +528,7 @@ fn parse_json(bytes: &[u8]) -> Result { window: DEFAULT_WINDOW, window_exact: false, cdn_size: sizes.get(&guid).copied().unwrap_or(0), + secret: [0; 4], }; match chunk_index.get(&guid) { Some(&at) => chunks[at] = info, @@ -647,6 +676,19 @@ pub mod testing { for c in &m.chunks { cl.extend_from_slice(&(c.cdn_size as i64).to_le_bytes()); } + if m.version >= 22 { + for c in &m.chunks { + for v in c.secret { + cl.extend_from_slice(&v.to_le_bytes()); + } + } + for c in &m.chunks { + cl.extend_from_slice(&(c.cdn_size as u32).to_le_bytes()); + } + for _ in &m.chunks { + cl.extend_from_slice(&[5; 16]); + } + } cl.extend_from_slice(&[9, 9, 9]); let mut fl = vec![0u8]; @@ -717,6 +759,7 @@ pub mod testing { window, window_exact: true, cdn_size: 1000, + secret: [0; 4], } } } @@ -827,8 +870,43 @@ mod tests { assert!(parse(&[0x0C, 0xC0]).is_err()); } + #[test] + fn secret_era_manifests_read_chunk_secrets_and_use_chunks_v5_paths() { + let mut s = sample(true, true); + s.version = 24; + s.chunks[1].secret = [0xDEADBEEF, 7, 0, 1]; + let m = parse(&build(&s)).unwrap(); + assert_eq!(m.version, 24); + assert_eq!(m.chunk_folder(), "ChunksV5"); + assert_eq!(m.chunks[0].secret, [0; 4]); + assert_eq!(m.chunks[1].secret, [0xDEADBEEF, 7, 0, 1]); + assert_eq!(m.chunks[1].cdn_size, 1000); + assert_eq!(m.chunk_path(&m.chunks[0]), "ChunksV5/plain/01/7s2riWdFIwE_AQAAAAIAAAAAAAAAAAAAgA.chunk"); + assert_eq!( + m.chunk_path(&m.chunks[1]), + "ChunksV5/776t3gcAAAAAAAAAAQAAAA/02/7c2riWdFIwE_AgAAAAMAAAAAAAAAAAAAgA.chunk" + ); + assert_eq!(m.files.len(), 3); + assert_eq!(m.files[0].parts[1].guid, s.chunks[1].guid); + } + + #[test] + fn pre_secret_manifests_keep_hex_chunk_paths() { + let m = parse(&build(&sample(false, true))).unwrap(); + assert_eq!(m.chunks[0].secret, [0; 4]); + let mut c = m.chunks[0].clone(); + c.secret = [9, 9, 9, 9]; + assert_eq!( + m.chunk_path(&c), + format!("ChunksV4/01/{:016X}_00000001000000020000000080000000.chunk", c.rolling_hash) + ); + } + #[test] fn chunk_folder_per_version_and_variant() { + assert_eq!(chunk_folder(Variant::Binary, 24), "ChunksV5"); + assert_eq!(chunk_folder(Variant::Binary, 22), "ChunksV5"); + assert_eq!(chunk_folder(Variant::Binary, 21), "ChunksV4"); assert_eq!(chunk_folder(Variant::Binary, 15), "ChunksV4"); assert_eq!(chunk_folder(Variant::Binary, 14), "ChunksV3"); assert_eq!(chunk_folder(Variant::Binary, 6), "ChunksV3");