tirr-c / jxl-oxide

Pure Rust implementation of JPEG XL decoder
Apache License 2.0
308 stars 13 forks source link

Panic on VarDCT animated or small images in `adaptive_lf_smoothing_impl` #24

Closed EugeneVert closed 1 year ago

EugeneVert commented 1 year ago

Bug description Jxl-oxide panics during decoding of VarDCT frames if at least one of the frame dimensions ≤ 8.

This not only applies to small images, but also to animations with repeating frames.

Error message

INFO jxl_dec: Image dimension: 1x1
thread 'main' panicked at 'attempt to subtract with overflow', crates/jxl-render/src/vardct/generic.rs:20:44

Example JXL image: anim 1x1 d1 jxl

EugeneVert commented 1 year ago

Big animated VarDCT image with repeating frames example:

convert -size 512x512 canvas:white '1.png' 
convert -size 512x512 canvas:gray '2.png'
convert -delay 10 '1.png' '2.png' 'anim.apng'
cjxl 'anim.apng' -d 1 'anim.jxl'

jxl-info (reduced)

JPEG XL image
  Image dimension: 512x512
  Bit depth: 8 bits
  XYB encoded, suggested display color encoding:
    Colorspace: Grayscale
    White point: D65
    Primaries: sRGB
    Transfer function: sRGB
  Animated (1000/1 ticks per second)
Frame #0
  512x512; (0, 0)
Frame #1
  1x1; (0, 0)
Frame #2
  1x1; (0, 0)
Frame #3
  512x512; (0, 0)
Frame #4
  1x1; (0, 0)
Frame #5
  1x1; (0, 0)

JXL image: anim 512x512 d1 jxl