jasper icon indicating copy to clipboard operation
jasper copied to clipboard

Security: size_t overflow in jas_stream_peek

Open xmoezzz opened this issue 3 months ago • 2 comments

Hi, I am writing to report a size_t overflow that I discovered in this project.

  1. Vulnerability Summary:
/root/build/jasper-4.2.8/src/libjasper/base/jas_stream.c:713:22: runtime error: unsigned integer overflow: 0 - 1 cannot be represented in type 'size_t' (aka 'unsigned long')
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /root/build/jasper-4.2.8/src/libjasper/base/jas_stream.c:713:22 in
  1. Affected Version The latest release version 4.2.8.

  2. Reproduce

  • Command line:
jasper "--input" "A" "--output" "B" "--input-format" "pg" "--output-format" "jpc" "" ""
  • Compile the executable binary with "--fsanitizer=undefined" flag.
  • Corrupted input data A (unzip A.zip first):

A.zip

Best regards,

xmoezzz avatar Nov 11 '25 01:11 xmoezzz

@xmoezzz: I cannot reproduce this problem with the latest commit of JasPer on the master branch. When I run the jasper program (built with ASan and UBSan enabled) with the command line that you specified, I get the following output:

warning: ignoring bogus command line argument 
warning: ignoring bogus command line argument 
invalid PGX signature
cannot get header
jas_image_decode: decode operation failed
error: cannot load image data

Did you try the latest commit on the master branch?

mdadams avatar Nov 13 '25 16:11 mdadams

Thanks for your reply! I tried the latest commit of the master branch (7576bf0).

This is my build command:

CC=clang CXX=clang++ \
cmake -DCMAKE_BUILD_TYPE=Debug \
      -DCMAKE_C_FLAGS="-fsanitize=address -fno-omit-frame-pointer -fsanitize=signed-integer-overflow -fsanitize=unsigned-integer-overflow -fsanitize=shift -fsanitize=bounds -fsanitize=null -fsanitize=pointer-overflow -g -O1" \
      -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address,undefined" \
      -DCMAKE_SHARED_LINKER_FLAGS="-fsanitize=address,undefined" \
      ../jasper

xmoezzz avatar Nov 17 '25 10:11 xmoezzz