#12238·pixijs

DDS parser hard-codes 4 bytes per pixel for uncompressed mipmaps

Author: mf3493297-pngCreated Sep 27, 2026Updated Sep 27, 2026

DDS parser hard-codes 4 bytes per pixel for uncompressed mipmaps

Current behavior

parseDDS() accepts several uncompressed DXGI formats, including R8_UNORM, R8G8_UNORM, and R16_UNORM. A one-level texture in these formats parses successfully, but a valid file with multiple mip levels throws a RangeError.

The failure reproduces on the current dev branch at commit 27071aa0096d8749bfdb189857c58178c30cd153 in headed Firefox.

Expected behavior

The parser should calculate each uncompressed mip level using the selected format's actual bits per pixel. Valid uncompressed DDS textures should parse regardless of whether their texels occupy one, two, or four bytes.

Minimal reproduction

Run the following valid DX10 DDS files through parseDDS():

  • R8_UNORM, 4×4, one mip: succeeds with [16]
  • R8_UNORM, 4×4 and 2×2 mips: throws RangeError
  • R8G8_UNORM, 4×4 and 2×2 mips: throws RangeError
  • R16_UNORM, 4×4 and 2×2 mips: throws RangeError
  • R8G8B8A8_UNORM, 4×4 and 2×2 mips: succeeds with [64, 16]

Observed headed-Firefox result:

R8 one level        -> levels=1, sizes=[16]
R8 two levels       -> RangeError: out-of-bounds Uint8Array
RG8 two levels      -> RangeError: out-of-bounds Uint8Array
R16 two levels      -> RangeError: out-of-bounds Uint8Array
RGBA8 two levels    -> levels=2, sizes=[64,16]

Root cause

Affected code: src/compressed-textures/dds/parseDDS.ts, getMipmapLevelBuffers().

For every uncompressed format, the level size is calculated as:

typescript
const byteLength = blockBytes
    ? alignedWidth / 4 * alignedHeight / 4 * blockBytes
    : mipWidth * mipHeight * 4;

The fallback unconditionally assumes four bytes per pixel. This is correct for RGBA8, which explains why the existing RGBA8 mipmap test passes, but it is incorrect for supported one- and two-byte formats.

For a 4×4 R8_UNORM texture with 2×2 mip level, the file contains 16 + 4 bytes. The parser attempts to read 64 + 16 bytes and constructs a typed-array view beyond the file bounds.

Environment

Duplicate review

I searched open and closed issues and pull requests for:

  • DDS R8 mipmap
  • DDS uncompressed mipmap
  • parseDDS byte length
  • DDS RangeError / typed-array length

I found no exact issue or pull request for this calculation.

Suggested fix direction

Use a format-to-bytes-per-pixel mapping for uncompressed DDS levels instead of the hard-coded multiplier. Validate every computed level span against the remaining buffer before constructing the view.

Please consider assigning a bounty if this issue meets the program's impact criteria. I can provide a focused regression test and patch after triage.

Public runnable reproduction

Run npm ci && npm start, then open http://127.0.0.1:4173/dds/ in Firefox. The page prints REPRODUCED: and shows the three failing valid formats plus the two neighboring controls. Verified in headed Camoufox.