Created
January 3, 2019 10:09
-
-
Save apoleon/eb4e396b510f2bb5a925660dab09be79 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From: Markus Koschany <apo@debian.org> | |
Date: Thu, 3 Jan 2019 10:55:16 +0100 | |
Subject: CVE-2018-18873 | |
--- | |
src/libjasper/ras/ras_enc.c | 4 ++++ | |
1 file changed, 4 insertions(+) | |
diff --git a/src/libjasper/ras/ras_enc.c b/src/libjasper/ras/ras_enc.c | |
index 6e651bd..aaeff19 100644 | |
--- a/src/libjasper/ras/ras_enc.c | |
+++ b/src/libjasper/ras/ras_enc.c | |
@@ -248,6 +248,10 @@ static int ras_putdatastd(jas_stream_t *out, ras_hdr_t *hdr, jas_image_t *image, | |
hdr->length = hdr->height * rowsize; | |
+ if(data[0] == NULL || data[1] == NULL || data[2] == NULL) { | |
+ goto error; | |
+ } | |
+ | |
for (y = 0; y < hdr->height; y++) { | |
for (i = 0; i < numcmpts; ++i) { | |
if (jas_image_readcmpt(image, cmpts[i], 0, y, |
Hi,
I don't think the additional condition is necessary because the data array is initialized here
for (i = 0; i < 3; ++i) {
data[i] = 0;
}
We then only goto error when at least one of the conditions is true data[0] == NULL || data[1] == NULL || data[2] == NULL. That should catch the gray image case too.
I mean the gray image case should not goto error. Jasper has a function to deal with the gray image.
src
if (RAS_ISRGB(hdr)) { // deal with the rgb image
v = RAS_RED((jas_matrix_getv(data[0], x))) |
RAS_GREEN((jas_matrix_getv(data[1], x))) | // crash in here
RAS_BLUE((jas_matrix_getv(data[2], x)));
} else {
L267: v = (jas_matrix_getv(data[0], x)); // deal with the gray image
}
In a normal gray ras image(not my poc),the value numcmpts is 1 and data[1],data[2] is NULL, and binary goto line 267.
My poc make binary do with a gray ras as a rgb ras,which leads to a crash.
In your patch, the binary goto error when processing a gray image. because data[1],data[2] is NULL in the gray image.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
maybe add a check
if the type of a ras image is GRAY, your check will mistake. GRAY raw image also has no data[1] ,data[2]
of course, my fix is not perfect,and is just a sample.
btw, the things you doing is cool, I want to do it .