Bug 694111 - Seg faults found by fuzzing in jbig2_huffman_get (jbig2_huffman.c:255)
Summary: Seg faults found by fuzzing in jbig2_huffman_get (jbig2_huffman.c:255)
Status: RESOLVED FIXED
Alias: None
Product: MuPDF
Classification: Unclassified
Component: fuzzing (show other bugs)
Version: unspecified
Hardware: PC Linux
: P4 normal
Assignee: Henry Stiles
URL:
Keywords: bountiable
Depends on:
Blocks:
 
Reported: 2013-05-27 16:51 UTC by Marcos H. Woehrmann
Modified: 2013-08-30 12:28 UTC (History)
2 users (show)

See Also:
Customer:
Word Size: 64


Attachments
log.txt (84.10 KB, text/plain)
2013-05-27 16:51 UTC, Marcos H. Woehrmann
Details
patch (2.57 KB, patch)
2013-07-12 07:56 UTC, zeniko
Details | Diff
revised.patch (2.69 KB, patch)
2013-08-30 11:50 UTC, Robin Watts
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Marcos H. Woehrmann 2013-05-27 16:51:35 UTC
Created attachment 9745 [details]
log.txt

Seg faults in the 64 bit build of mupdf were found by fuzzing in jbig2_huffman_get while reading these file(s). See the attached log.txt for details.

mupdf__3324.pdf.asan.50.2585.pgmraw.200.1
mupdf__3324.pdf.asan.50.2585.ppmraw.200.1
mupdf__3324.pdf.asan.50.2585.ppmraw.72.0
Comment 1 Robin Watts 2013-06-06 12:53:02 UTC
This one is still around.
Comment 2 Henry Stiles 2013-06-09 18:35:39 UTC
These problems are Bountible to Shelly and Simon (only) under the arrangement we set up previously for jbig2 and jpeg 2000 problems.  If you 2 can divide them fairly that's great if not I'll review them and assign them.  Let me know.
Comment 3 zeniko 2013-06-11 18:49:59 UTC
Marcos: The file 3324.pdf.asan.50.2585 seems to have been missing from the mupdf.zip you've shared with us. Could you please send it to me so that I can start looking into this issue?
Comment 4 Ken Sharp 2013-06-12 12:40:34 UTC
This (and a number of others) are I think decoder problems, so reassigning to Henry.
Comment 5 zeniko 2013-07-05 11:24:12 UTC
Thanks for the file, Marcos.

This file causes a heap overflow due to insufficient checks in jbig2_image_compose. Proposed fix: https://github.com/zeniko/jbig2dec/commit/9c232373bf4ec2df6148b1bdac5b95af2f93cea5
Comment 6 zeniko 2013-07-05 12:57:55 UTC
BTW: This might be the same issue as bug 694362.
Comment 7 zeniko 2013-07-12 07:56:26 UTC
Created attachment 10059 [details]
patch

Henry: This patch still needs your stamp of approval before it can land.
Comment 8 Henry Stiles 2013-07-12 15:28:59 UTC
If it passes the regression tests please commit.
Comment 9 zeniko 2013-07-26 13:22:14 UTC
This patch passed a cluster run (tested with MuPDF).
Comment 10 Henry Stiles 2013-08-30 11:17:19 UTC
The patch cannot be applied directly to the ghostscript tree because it was created from the mupdf tree.  I believe git am will not work across repositories because it depends on hash numbers.  The error is: git am 'file' does not exist in index.  I assume that refers to hash in the patch which presumably is an ancestor of the file being modified.  We really must do something about the multiple repository nonsense, but in the meantime I'll apply the patch and log manually.
Comment 11 Robin Watts 2013-08-30 11:50:13 UTC
Created attachment 10159 [details]
revised.patch

Revised patch to make it work with gs.
Comment 12 Robin Watts 2013-08-30 12:02:10 UTC
(In reply to comment #11)
> Created attachment 10159 [details]
> revised.patch
> 
> Revised patch to make it work with gs.

For clarity, I should say that the patch contents are identical. I just tweaked the paths in the patch so it will apply to the gs repo rather than the standalone jbig2dec one.
Comment 13 Henry Stiles 2013-08-30 12:28:15 UTC
My comment about the index was incorrect as Robin says in Comment 10 only the pathname in the patch needs correcting.

Checked into master:

commit f7064096ceac3d6c148096a936e1ea10fd8f0c55
Author: zeniko <zeniko@gmail.com>
Date:   Fri Jul 5 13:11:58 2013 +0200

    Bug 694111: prevent heap overflow

    jbig2_image_compose fails to ensure that the destination rectangle lies
    entirely within the destination buffer (in the case of the file
    3324.pdf.asan.50.2585, this happens due to a huge value for y). Adding a
    new check which makes sure that...

    @ y * dst->stride + leftbyte doesn't overflow
    @ x and leftbyte don't overflow to the next line
    @ h * dst->stride doesn't overflow
    @ all values read are within the destination buffer

    The file 3324.pdf.asan.50.2585 also demonstrates a memory leak where the
    glyph isn't properly released if jbig2_image_compose fails.