PE: reject out-of-image TLS callback VAs in va_to_rva #2530

Open
reeledMarek wants to merge 1 commit from upstream-pr/2532 into main
reeledMarek commented 2026-11-25 15:23:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-25T15:23:42Z.


Problem

victory_pe::image::va_to_rva only checked that va - image_base fit in u32, never that the resulting RVA was < size_of_image.

Because victory-loader calls parsed TlsInfo::callback_rvas directly as function pointers at base + rva, a TLS callback VA in [image_base + size_of_image, image_base + 4 GiB) passed ImageInfo::parse and caused an out-of-image jump.

Fix

  • Pass opt.size_of_image() into parse_tls and va_to_rva, filtering rva < size_of_image.

Testing

  • Added synthetic test rejects_tls_callback_outside_size_of_image in crates/victory-pe/src/image.rs.
  • Verified cargo test -p victory-pe --locked rejects_tls_callback_outside_size_of_image and Windows cross-clippy (-D warnings).
<!-- greyfinch-sync:Marvisak/VIctory:issue:6607869536 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2532). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-25T15:23:42Z. --- ### Problem `victory_pe::image::va_to_rva` only checked that `va - image_base` fit in `u32`, never that the resulting RVA was `< size_of_image`. Because `victory-loader` calls parsed `TlsInfo::callback_rvas` directly as function pointers at `base + rva`, a TLS callback VA in `[image_base + size_of_image, image_base + 4 GiB)` passed `ImageInfo::parse` and caused an out-of-image jump. ### Fix - Pass `opt.size_of_image()` into `parse_tls` and `va_to_rva`, filtering `rva < size_of_image`. ### Testing - Added synthetic test `rejects_tls_callback_outside_size_of_image` in `crates/victory-pe/src/image.rs`. - Verified `cargo test -p victory-pe --locked rejects_tls_callback_outside_size_of_image` and Windows cross-clippy (`-D warnings`).
Marvisak commented 2026-11-25 16:09:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:53:17Z.


Automated triage for the maintainers.

Recommended for a look. va_to_rva in crates/victory-pe/src/image.rs now rejects RVAs at or past SizeOfImage, so parse_tls no longer accepts TLS callback (or callback array) VAs outside the image; these RVAs are called directly in victory-loader's windows.rs, and the check matches the size_of_image bound already applied to import slots. The new test uses the existing synthetic_image helper (SizeOfImage 0x2000) and checks both the accepted and the rejected case. CI (clippy + tests on Windows): passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167401212 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2532#issuecomment-7167401212). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T15:53:17Z. --- <!-- victory-triage v1 head=9e35b94dec37c9db98b96e9d950be43c96f450cb verdict=merge-candidate at=2026-11-25T15:53:07Z --> Automated triage for the maintainers. Recommended for a look. `va_to_rva` in crates/victory-pe/src/image.rs now rejects RVAs at or past `SizeOfImage`, so `parse_tls` no longer accepts TLS callback (or callback array) VAs outside the image; these RVAs are called directly in victory-loader's windows.rs, and the check matches the `size_of_image` bound already applied to import slots. The new test uses the existing `synthetic_image` helper (SizeOfImage 0x2000) and checks both the accepted and the rejected case. CI (clippy + tests on Windows): passing. --- _Generated by [Claude Code](https://claude.ai/code)_
studiostephe commented 2026-11-25 18:02:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by studiostephe on 2026-11-25T17:05:23Z.


va_to_rva (image.rs:434) only checks that va - image_base fits in a u32 — never that the resulting RVA is below size_of_image. victory-loader calls parsed TlsInfo::callback_rvas directly as function pointers at base + rva (windows.rs:317), so a TLS callback VA in [image_base + size_of_image, image_base + 4 GiB) passes ImageInfo::parse and causes an out-of-image jump.

Pass opt.size_of_image() through parse_tls and reject any TLS VA whose RVA is past the image (both the callback array pointer and each callback slot).

diff --git a/crates/victory-pe/src/image.rs b/crates/victory-pe/src/image.rs
index b22808b..39e867a 100644
--- a/crates/victory-pe/src/image.rs
+++ b/crates/victory-pe/src/image.rs
@@ -191,7 +191,7 @@ impl ImageInfo {
         };
         let delay_imports = parse_delay_imports(&file, opt.size_of_image())?;
         let exports = parse_exports(&file, opt.image_base())?;
-        let tls = parse_tls(&file, data, opt.image_base())?;
+        let tls = parse_tls(&file, data, opt.image_base(), opt.size_of_image())?;
         let codeview = file.pdb_info()?.map(|cv| CodeViewInfo {
             pdb_path: String::from_utf8_lossy(cv.path()).into_owned(),
             guid: cv.guid(),
@@ -395,6 +395,7 @@ fn parse_tls(
     file: &PeFile64<'_>,
     data: &[u8],
     image_base: u64,
+    size_of_image: u32,
 ) -> Result<Option<TlsInfo>, PeError> {
     let Some(dd) = file.data_directory(pe::IMAGE_DIRECTORY_ENTRY_TLS) else {
         return Ok(None);
@@ -409,10 +410,9 @@ fn parse_tls(
         .ok_or_else(|| PeError::Malformed("TLS directory outside of sections".into()))?;
     let callbacks_va = layout::read_u64(tls, layout::TLS64_ADDRESS_OF_CALLBACKS)
         .ok_or_else(|| PeError::Malformed("truncated TLS directory".into()))?;
-
     let mut callback_rvas = Vec::new();
     if callbacks_va != 0 {
-        let array_rva = va_to_rva(callbacks_va, image_base)?;
+        let array_rva = va_to_rva(callbacks_va, image_base, size_of_image)?;
         let array = sections
             .pe_data_at(data, array_rva)
             .ok_or_else(|| PeError::Malformed("TLS callback array outside of sections".into()))?;
@@ -421,7 +421,7 @@ fn parse_tls(
             if va == 0 {
                 break;
             }
-            callback_rvas.push(va_to_rva(va, image_base)?);
+            callback_rvas.push(va_to_rva(va, image_base, size_of_image)?);
         }
     }
     Ok(Some(TlsInfo {
@@ -431,10 +431,17 @@ fn parse_tls(
     }))
 }
 
-fn va_to_rva(va: u64, image_base: u64) -> Result<u32, PeError> {
-    va.checked_sub(image_base)
+fn va_to_rva(va: u64, image_base: u64, size_of_image: u32) -> Result<u32, PeError> {
+    let rva = va
+        .checked_sub(image_base)
         .and_then(|rva| u32::try_from(rva).ok())
-        .ok_or_else(|| PeError::Malformed(format!("VA 0x{va:x} is outside the image")))
+        .ok_or_else(|| PeError::Malformed(format!("VA 0x{va:x} is outside the image")))?;
+    if rva >= size_of_image {
+        return Err(PeError::Malformed(format!(
+            "VA 0x{va:x} maps past the image (RVA 0x{rva:x} >= size of image 0x{size_of_image:x})"
+        )));
+    }
+    Ok(rva)
 }
 
 #[cfg(test)]
@@ -692,4 +699,72 @@ mod tests {
             ]
         );
     }
+
+    /// The same synthetic image, but with a TLS callback array that is empty
+    /// (the stop slot first): the image is accepted with no callbacks.
+    fn synthetic_image_no_callbacks() -> Vec<u8> {
+        let mut body = vec![0u8; 0x200];
+        let put64 =
+            |b: &mut Vec<u8>, at: usize, v: u64| b[at..at + 8].copy_from_slice(&v.to_le_bytes());
+        put64(&mut body, 8, 0x1_8000_0000 + 0x1040);
+        put64(&mut body, 24, 0x1_8000_0000 + 0x1040);
+        let mut data = synthetic_image(&body);
+        let opt = 0x58;
+        let put32 =
+            |b: &mut Vec<u8>, at: usize, v: u32| b[at..at + 4].copy_from_slice(&v.to_le_bytes());
+        data[opt + 112..opt + 116].fill(0);
+        data[opt + 116..opt + 120].fill(0);
+        put32(&mut data, opt + 112 + 9 * 8, 0x1000);
+        put32(&mut data, opt + 112 + 9 * 8 + 4, 0x200);
+        data
+    }
+
+    #[test]
+    fn accepts_tls_image_without_callbacks() {
+        let info = ImageInfo::parse(&synthetic_image_no_callbacks()).unwrap();
+        let tls = info.tls.as_ref().expect("TLS directory present");
+        assert!(tls.callback_rvas.is_empty());
+    }
+
+    #[test]
+    fn rejects_tls_callback_outside_size_of_image() {
+        // The synthetic image spans RVA 0..0x2000, so an in-range VA is one
+        // whose RVA is below 0x2000. A callback VA at image base + 0x40_0000
+        // is within 4 GiB of the base but far past the image: it used to pass
+        // parsing and be called as a function pointer by the loader.
+        let mut body = vec![0u8; 0x200];
+        let put32 =
+            |b: &mut Vec<u8>, at: usize, v: u32| b[at..at + 4].copy_from_slice(&v.to_le_bytes());
+        let put64 =
+            |b: &mut Vec<u8>, at: usize, v: u64| b[at..at + 8].copy_from_slice(&v.to_le_bytes());
+        // IMAGE_TLS_DIRECTORY64: AddressOfIndex (0), AddressOfCallBacks
+        // (offset 8, base + 0x1040), AddressOfCallBacks (offset 24, same).
+        put32(&mut body, 0, 0);
+        put32(&mut body, 4, 0);
+        put64(&mut body, 8, 0x1_8000_0000 + 0x1040);
+        put64(&mut body, 24, 0x1_8000_0000 + 0x1040);
+        // Callback array at RVA 0x1040: one out-of-image callback, a stop.
+        put64(&mut body, 0x40, 0x1_8000_4000);
+        put64(&mut body, 0x48, 0);
+
+        let mut data = synthetic_image(&body);
+        // The synthetic image's only data directory is the export table
+        // (index 0); disable it and add the TLS directory (index 9, rva
+        // 0x1000, size 0x200) so the export and TLS tables do not alias.
+        let opt = 0x58;
+        data[opt + 112..opt + 116].fill(0);
+        data[opt + 116..opt + 120].fill(0);
+        put32(&mut data, opt + 112 + 9 * 8, 0x1000);
+        put32(&mut data, opt + 112 + 9 * 8 + 4, 0x200);
+
+        // Baseline sanity: the same image with an empty callback array is
+        // accepted, so the rejection below is the size check, not the TLS
+        // plumbing.
+        let good = synthetic_image_no_callbacks();
+        let info = ImageInfo::parse(&good).unwrap();
+        assert!(info.tls.unwrap().callback_rvas.is_empty());
+
+        assert!(matches!(
+            ImageInfo::parse(&data),
+            Err(PeError::Malformed(_))
+        ));
+    }
 }

Verified (native, M1 Mac, Rust 1.98.1):

  • cargo test -p victory-pe --locked — 34 passed; the 4 failures (parses_own_test_binary, rva_to_file_offset_maps_entry_point, rva_to_file_offset_rejects_offsets_past_4_gib, rejects_iat_outside_image) are pre-existing on unpatched main (the own_image() tests read the test binary, which fails in this environment) and are unrelated to this change.
  • New tests rejects_tls_callback_outside_size_of_image and accepts_tls_image_without_callbacks both pass.
  • Negative control: with the rva >= size_of_image check removed, rejects_tls_callback_outside_size_of_image fails (the out-of-image callback is accepted), confirming the test exercises the fix.
  • rustfmt --edition 2024 --check clean; cargo clippy -p victory-pe --all-targets --locked — 0 warnings.

Not covered: the fix is verified at the parse level (the RVA bound is enforced). I could not run the loader end-to-end (no Windows), so the out-of-image-jump scenario is proven by the parse rejection, not by a runtime test.

qwen3.8_27b running locally on an M1 Mac
shout out to Digital Debris Los Angeles

<!-- greyfinch-sync:Marvisak/VIctory:comment:7168986717 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2532#issuecomment-7168986717). Originally posted by [studiostephe](https://github.com/studiostephe) on 2026-11-25T17:05:23Z. --- `va_to_rva` (image.rs:434) only checks that `va - image_base` fits in a `u32` — never that the resulting RVA is below `size_of_image`. `victory-loader` calls parsed `TlsInfo::callback_rvas` directly as function pointers at `base + rva` (windows.rs:317), so a TLS callback VA in `[image_base + size_of_image, image_base + 4 GiB)` passes `ImageInfo::parse` and causes an out-of-image jump. Pass `opt.size_of_image()` through `parse_tls` and reject any TLS VA whose RVA is past the image (both the callback array pointer and each callback slot). ```diff diff --git a/crates/victory-pe/src/image.rs b/crates/victory-pe/src/image.rs index b22808b..39e867a 100644 --- a/crates/victory-pe/src/image.rs +++ b/crates/victory-pe/src/image.rs @@ -191,7 +191,7 @@ impl ImageInfo { }; let delay_imports = parse_delay_imports(&file, opt.size_of_image())?; let exports = parse_exports(&file, opt.image_base())?; - let tls = parse_tls(&file, data, opt.image_base())?; + let tls = parse_tls(&file, data, opt.image_base(), opt.size_of_image())?; let codeview = file.pdb_info()?.map(|cv| CodeViewInfo { pdb_path: String::from_utf8_lossy(cv.path()).into_owned(), guid: cv.guid(), @@ -395,6 +395,7 @@ fn parse_tls( file: &PeFile64<'_>, data: &[u8], image_base: u64, + size_of_image: u32, ) -> Result<Option<TlsInfo>, PeError> { let Some(dd) = file.data_directory(pe::IMAGE_DIRECTORY_ENTRY_TLS) else { return Ok(None); @@ -409,10 +410,9 @@ fn parse_tls( .ok_or_else(|| PeError::Malformed("TLS directory outside of sections".into()))?; let callbacks_va = layout::read_u64(tls, layout::TLS64_ADDRESS_OF_CALLBACKS) .ok_or_else(|| PeError::Malformed("truncated TLS directory".into()))?; - let mut callback_rvas = Vec::new(); if callbacks_va != 0 { - let array_rva = va_to_rva(callbacks_va, image_base)?; + let array_rva = va_to_rva(callbacks_va, image_base, size_of_image)?; let array = sections .pe_data_at(data, array_rva) .ok_or_else(|| PeError::Malformed("TLS callback array outside of sections".into()))?; @@ -421,7 +421,7 @@ fn parse_tls( if va == 0 { break; } - callback_rvas.push(va_to_rva(va, image_base)?); + callback_rvas.push(va_to_rva(va, image_base, size_of_image)?); } } Ok(Some(TlsInfo { @@ -431,10 +431,17 @@ fn parse_tls( })) } -fn va_to_rva(va: u64, image_base: u64) -> Result<u32, PeError> { - va.checked_sub(image_base) +fn va_to_rva(va: u64, image_base: u64, size_of_image: u32) -> Result<u32, PeError> { + let rva = va + .checked_sub(image_base) .and_then(|rva| u32::try_from(rva).ok()) - .ok_or_else(|| PeError::Malformed(format!("VA 0x{va:x} is outside the image"))) + .ok_or_else(|| PeError::Malformed(format!("VA 0x{va:x} is outside the image")))?; + if rva >= size_of_image { + return Err(PeError::Malformed(format!( + "VA 0x{va:x} maps past the image (RVA 0x{rva:x} >= size of image 0x{size_of_image:x})" + ))); + } + Ok(rva) } #[cfg(test)] @@ -692,4 +699,72 @@ mod tests { ] ); } + + /// The same synthetic image, but with a TLS callback array that is empty + /// (the stop slot first): the image is accepted with no callbacks. + fn synthetic_image_no_callbacks() -> Vec<u8> { + let mut body = vec![0u8; 0x200]; + let put64 = + |b: &mut Vec<u8>, at: usize, v: u64| b[at..at + 8].copy_from_slice(&v.to_le_bytes()); + put64(&mut body, 8, 0x1_8000_0000 + 0x1040); + put64(&mut body, 24, 0x1_8000_0000 + 0x1040); + let mut data = synthetic_image(&body); + let opt = 0x58; + let put32 = + |b: &mut Vec<u8>, at: usize, v: u32| b[at..at + 4].copy_from_slice(&v.to_le_bytes()); + data[opt + 112..opt + 116].fill(0); + data[opt + 116..opt + 120].fill(0); + put32(&mut data, opt + 112 + 9 * 8, 0x1000); + put32(&mut data, opt + 112 + 9 * 8 + 4, 0x200); + data + } + + #[test] + fn accepts_tls_image_without_callbacks() { + let info = ImageInfo::parse(&synthetic_image_no_callbacks()).unwrap(); + let tls = info.tls.as_ref().expect("TLS directory present"); + assert!(tls.callback_rvas.is_empty()); + } + + #[test] + fn rejects_tls_callback_outside_size_of_image() { + // The synthetic image spans RVA 0..0x2000, so an in-range VA is one + // whose RVA is below 0x2000. A callback VA at image base + 0x40_0000 + // is within 4 GiB of the base but far past the image: it used to pass + // parsing and be called as a function pointer by the loader. + let mut body = vec![0u8; 0x200]; + let put32 = + |b: &mut Vec<u8>, at: usize, v: u32| b[at..at + 4].copy_from_slice(&v.to_le_bytes()); + let put64 = + |b: &mut Vec<u8>, at: usize, v: u64| b[at..at + 8].copy_from_slice(&v.to_le_bytes()); + // IMAGE_TLS_DIRECTORY64: AddressOfIndex (0), AddressOfCallBacks + // (offset 8, base + 0x1040), AddressOfCallBacks (offset 24, same). + put32(&mut body, 0, 0); + put32(&mut body, 4, 0); + put64(&mut body, 8, 0x1_8000_0000 + 0x1040); + put64(&mut body, 24, 0x1_8000_0000 + 0x1040); + // Callback array at RVA 0x1040: one out-of-image callback, a stop. + put64(&mut body, 0x40, 0x1_8000_4000); + put64(&mut body, 0x48, 0); + + let mut data = synthetic_image(&body); + // The synthetic image's only data directory is the export table + // (index 0); disable it and add the TLS directory (index 9, rva + // 0x1000, size 0x200) so the export and TLS tables do not alias. + let opt = 0x58; + data[opt + 112..opt + 116].fill(0); + data[opt + 116..opt + 120].fill(0); + put32(&mut data, opt + 112 + 9 * 8, 0x1000); + put32(&mut data, opt + 112 + 9 * 8 + 4, 0x200); + + // Baseline sanity: the same image with an empty callback array is + // accepted, so the rejection below is the size check, not the TLS + // plumbing. + let good = synthetic_image_no_callbacks(); + let info = ImageInfo::parse(&good).unwrap(); + assert!(info.tls.unwrap().callback_rvas.is_empty()); + + assert!(matches!( + ImageInfo::parse(&data), + Err(PeError::Malformed(_)) + )); + } } ``` **Verified** (native, M1 Mac, Rust 1.98.1): - `cargo test -p victory-pe --locked` — 34 passed; the 4 failures (`parses_own_test_binary`, `rva_to_file_offset_maps_entry_point`, `rva_to_file_offset_rejects_offsets_past_4_gib`, `rejects_iat_outside_image`) are pre-existing on unpatched `main` (the `own_image()` tests read the test binary, which fails in this environment) and are unrelated to this change. - New tests `rejects_tls_callback_outside_size_of_image` and `accepts_tls_image_without_callbacks` both pass. - Negative control: with the `rva >= size_of_image` check removed, `rejects_tls_callback_outside_size_of_image` fails (the out-of-image callback is accepted), confirming the test exercises the fix. - `rustfmt --edition 2024 --check` clean; `cargo clippy -p victory-pe --all-targets --locked` — 0 warnings. **Not covered:** the fix is verified at the parse level (the RVA bound is enforced). I could not run the loader end-to-end (no Windows), so the out-of-image-jump scenario is proven by the parse rejection, not by a runtime test. qwen3.8_27b running locally on an M1 Mac shout out to Digital Debris Los Angeles
fuzeofficlal commented 2026-11-26 01:04:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T00:51:29Z.


Code review and Windows 11 verification at head 9e35b94dec37 merged cleanly onto main (63bcca43c6a0):

  • Code review (crates/victory-pe/src/image.rs:416-440):
    • va_to_rva rejects < ImageBase underflow via checked_sub, > 4 GiB overflow via u32::try_from, and >= SizeOfImage (including ImageBase + SizeOfImage and SizeOfImage == 0) via .filter(|&rva| rva < size_of_image).
    • parse_tls breaks on the null terminator (if va == 0 { break; }) before invoking va_to_rva, and callbacks_va is checked through both va_to_rva and sections.pe_data_at. Confirmed va_to_rva is private to image.rs with only these two call sites, protecting victory-loader/src/windows.rs:317 from out-of-image callback pointers.
  • Verified (Windows 11, Rust 1.98.1):
    • cargo xtask policy: 191 files ok; cargo clippy --locked -p victory-pe -p victory-loader --tests -- -D warnings: 0 warnings
    • victory-pe: 37/37 passed (including rejects_tls_callback_outside_size_of_image)
    • victory-loader: 35/35 unit + 4/4 integration passed.

LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7179183081 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2532#issuecomment-7179183081). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T00:51:29Z. --- Code review and Windows 11 verification at head `9e35b94dec37` merged cleanly onto `main` (`63bcca43c6a0`): - **Code review (`crates/victory-pe/src/image.rs:416-440`)**: - `va_to_rva` rejects `< ImageBase` underflow via `checked_sub`, `> 4 GiB` overflow via `u32::try_from`, and `>= SizeOfImage` (including `ImageBase + SizeOfImage` and `SizeOfImage == 0`) via `.filter(|&rva| rva < size_of_image)`. - `parse_tls` breaks on the null terminator (`if va == 0 { break; }`) before invoking `va_to_rva`, and `callbacks_va` is checked through both `va_to_rva` and `sections.pe_data_at`. Confirmed `va_to_rva` is private to `image.rs` with only these two call sites, protecting `victory-loader/src/windows.rs:317` from out-of-image callback pointers. - **Verified (Windows 11, Rust 1.98.1)**: - `cargo xtask policy`: `191 files ok`; `cargo clippy --locked -p victory-pe -p victory-loader --tests -- -D warnings`: 0 warnings - `victory-pe`: **37/37 passed** (including `rejects_tls_callback_outside_size_of_image`) - `victory-loader`: **35/35 unit + 4/4 integration passed**. LGTM.
fuzeofficlal commented 2026-11-26 14:01:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T13:18:19Z.

Review: APPROVED


Reviewed and verified 9e35b94d merged locally onto origin/main (63bcca43) on Windows 11 x64 (Rust 1.98.1 MSVC; synthetic tests only, no game files).

Verification

  • git merge-tree against origin/main (63bcca43): clean.
  • cargo xtask policy (PR head): 182 files ok.
  • cargo clippy --locked -p victory-pe -p victory-loader --all-targets -- -D warnings (default and --all-features, PR head and merged): 0 warnings.
  • Dev tests (merged): cargo test --locked -p victory-pe -p victory-loader — victory-pe 37 passed, 0 failed (including rejects_tls_callback_outside_size_of_image), victory-loader 35 unit + 4 integration passed, 0 failed.
  • Release tests (merged): cargo test --locked --release -p victory-pe — 37 passed, 0 failed.
  • Boundary checks (dev & --release): verified va < image_base, va == 0, va == image_base, va == image_base + size_of_image - 1, va == image_base + size_of_image, va == image_base + (1 << 32), and size_of_image == 0.

Review Notes

  • Filtering rva < size_of_image in va_to_rva (crates/victory-pe/src/image.rs:435-440) and passing opt.size_of_image() through parse_tls (:194, :394-433) closes the out-of-image TLS callback pointer gap ahead of victory-loader's callback invocation, matching the size_of_image bound already enforced on import slots.
  • parse_tls breaks on the 0 terminator before calling va_to_rva, and va_to_rva is private to image.rs with only these two call sites, so legitimate PE images are unaffected.

Looks good to merge.

<!-- greyfinch-sync:Marvisak/VIctory:review:6074798730 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2532#pullrequestreview-6074798730). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T13:18:19Z. **Review:** APPROVED --- Reviewed and verified `9e35b94d` merged locally onto `origin/main` (`63bcca43`) on Windows 11 x64 (Rust `1.98.1` MSVC; synthetic tests only, no game files). ### Verification - `git merge-tree` against `origin/main` (`63bcca43`): clean. - `cargo xtask policy` (PR head): `182 files ok`. - `cargo clippy --locked -p victory-pe -p victory-loader --all-targets -- -D warnings` (default and `--all-features`, PR head and merged): 0 warnings. - **Dev tests (merged):** `cargo test --locked -p victory-pe -p victory-loader` — `victory-pe` **37 passed, 0 failed** (including `rejects_tls_callback_outside_size_of_image`), `victory-loader` **35 unit + 4 integration passed, 0 failed**. - **Release tests (merged):** `cargo test --locked --release -p victory-pe` — **37 passed, 0 failed**. - **Boundary checks (dev & `--release`):** verified `va < image_base`, `va == 0`, `va == image_base`, `va == image_base + size_of_image - 1`, `va == image_base + size_of_image`, `va == image_base + (1 << 32)`, and `size_of_image == 0`. ### Review Notes - Filtering `rva < size_of_image` in `va_to_rva` (`crates/victory-pe/src/image.rs:435-440`) and passing `opt.size_of_image()` through `parse_tls` (`:194`, `:394-433`) closes the out-of-image TLS callback pointer gap ahead of `victory-loader`'s callback invocation, matching the `size_of_image` bound already enforced on import slots. - `parse_tls` breaks on the `0` terminator before calling `va_to_rva`, and `va_to_rva` is private to `image.rs` with only these two call sites, so legitimate PE images are unaffected. Looks good to merge.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2532:upstream-pr/2532'
git switch 'upstream-pr/2532'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2532'
git switch 'upstream-pr/2532'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2532'
git switch 'upstream-pr/2532'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2532'
git switch 'main'
git merge --squash 'upstream-pr/2532'
git switch 'main'
git merge --ff-only 'upstream-pr/2532'
git switch 'main'
git merge 'upstream-pr/2532'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!2530
No description provided.