Skip to content

Harden BLP mip bounds and palette regression coverage - #63

Open
draxxris wants to merge 1 commit into
wowemulation-dev:mainfrom
draxxris:blp-mip-and-raw1-regressions
Open

Harden BLP mip bounds and palette regression coverage#63
draxxris wants to merge 1 commit into
wowemulation-dev:mainfrom
draxxris:blp-mip-and-raw1-regressions

Conversation

@draxxris

Copy link
Copy Markdown

Pull Request

Summary

Some valid BLP2 files contain zero-sized trailing mipmap slots. The parser should stop at those slots instead of reporting false out-of-bounds errors.

Checked offset arithmetic also prevents malformed headers from causing integer overflow or invalid buffer slicing.

The RAW1 test protects the existing palette channel-order behavior.

From: https://forum.warmane.com/showthread.php?t=464195

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing
    functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test improvements
  • Build system/dependency changes
  • Security fix

Changes Made

  • Add checked arithmetic for BLP mipmap offsets and sizes.
  • Reject mip payloads that exceed the source buffer.
  • Treat zero-sized trailing mipmap slots as valid terminators.
  • Add a RAW1 palette regression test for BGRX-to-RGBA conversion.
  • Valid BLP mipmaps retain their existing behavior.
  • Malformed offsets return parsing errors.
  • Zero-sized trailing mipmaps are accepted as terminators.
  • No production RAW1 decoding behavior changes.

Testing

Test Cases Added/Modified

  • Unit tests
  • Integration tests
  • Compliance tests (StormLib compatibility)
  • Performance benchmarks
  • Manual testing

Test Results

$ cargo test -p wow-blp
   Compiling wow-blp v0.7.0 (/home/gordon/workspace/felix/vendor/warcraft-rs/file-formats/graphics/wow-blp)
    Finished `test` profile [unoptimized + debuginfo] target(s) in 3.85s
     Running unittests src/lib.rs (target/debug/deps/wow_blp-c7457cb23b442109)

running 18 tests
test convert::jpeg::tests::test_fetch_common_header ... ok
test convert::raw1::tests::bgrx_palette_decodes_to_rgba ... ok
test path::tests::test_blp0_path ... ok
test parser::bounds::tests::test_size_out_of_bounds ... ok
test parser::direct::blp2::tests::zero_sized_trailing_mipmaps_are_ignored ... ok
test encode::tests::test_sorting ... ok
test types::header::tests::test_alpha_type_conversion ... ok
test types::header::tests::test_alpha_type_wow_version_support ... ok
test encode::primitives::tests::test_push_le_u32 ... ok
test parser::bounds::tests::test_get_bounded_slice ... ok
test parser::bounds::tests::test_offset_out_of_bounds ... ok
test convert::dxtn::tests::test_dxt1_valid_buffer_succeeds ... ok
test convert::dxtn::tests::test_empty_buffer_produces_blank_image ... ok
test convert::dxtn::tests::test_dxt5_undersized_buffer_succeeds_with_padding ... ok
test convert::dxtn::tests::test_dxt3_undersized_buffer_succeeds_with_padding ... ok
test types::header::tests::test_mipmap_count ... ok
test parser::bounds::tests::test_valid_bounds ... ok
test types::version::tests::known_magics ... ok

test result: ok. 18 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

   Doc-tests wow_blp

running 6 tests
test file-formats/graphics/wow-blp/src/lib.rs - (line 109) - compile ... ok
test file-formats/graphics/wow-blp/src/lib.rs - (line 125) - compile ... ok
test file-formats/graphics/wow-blp/src/lib.rs - (line 176) - compile ... ok
test file-formats/graphics/wow-blp/src/lib.rs - (line 25) - compile ... ok
test file-formats/graphics/wow-blp/src/lib.rs - (line 35) - compile ... ok
test file-formats/graphics/wow-blp/src/lib.rs - (line 153) ... ok

test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

all doctests ran in 1.31s; merged doctests compilation took 1.29s
...

Tested On

  • Linux
  • macOS
  • Windows
  • Cross-compilation targets

WoW Versions Tested

  • 1.12.1 (Vanilla)
  • 2.4.3 (TBC)
  • 3.3.5a (WotLK)
  • 4.3.4 (Cataclysm)
  • 5.4.8 (MoP)
  • Other: Custom game engine

Use checked offset and size arithmetic for DXT mip payloads, stop cleanly at zero-sized trailing mip slots, and add regression coverage for RAW1 palette channel conversion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant