summaryrefslogtreecommitdiffstats
path: root/meta/recipes-graphics/jpeg/files/CVE-2020-35538-1.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-graphics/jpeg/files/CVE-2020-35538-1.patch')
-rw-r--r--meta/recipes-graphics/jpeg/files/CVE-2020-35538-1.patch457
1 files changed, 457 insertions, 0 deletions
diff --git a/meta/recipes-graphics/jpeg/files/CVE-2020-35538-1.patch b/meta/recipes-graphics/jpeg/files/CVE-2020-35538-1.patch
new file mode 100644
index 0000000000..8a52ed01e9
--- /dev/null
+++ b/meta/recipes-graphics/jpeg/files/CVE-2020-35538-1.patch
@@ -0,0 +1,457 @@
1From 9120a247436e84c0b4eea828cb11e8f665fcde30 Mon Sep 17 00:00:00 2001
2From: DRC <information@libjpeg-turbo.org>
3Date: Thu, 23 Jul 2020 21:24:38 -0500
4Subject: [PATCH] Fix jpeg_skip_scanlines() segfault w/merged upsamp
5
6The additional segfault mentioned in #244 was due to the fact that
7the merged upsamplers use a different private structure than the
8non-merged upsamplers. jpeg_skip_scanlines() was assuming the latter, so
9when merged upsampling was enabled, jpeg_skip_scanlines() clobbered one
10of the IDCT method pointers in the merged upsampler's private structure.
11
12For reasons unknown, the test image in #441 did not encounter this
13segfault (too small?), but it encountered an issue similar to the one
14fixed in 5bc43c7821df982f65aa1c738f67fbf7cba8bd69, whereby it was
15necessary to set up a dummy postprocessing function in
16read_and_discard_scanlines() when merged upsampling was enabled.
17Failing to do so caused either a segfault in merged_2v_upsample() (due
18to a NULL pointer being passed to jcopy_sample_rows()) or an error
19("Corrupt JPEG data: premature end of data segment"), depending on the
20number of scanlines skipped and whether the first scanline skipped was
21an odd- or even-numbered row.
22
23Fixes #441
24Fixes #244 (for real this time)
25
26Upstream-Status: Backport [https://github.com/libjpeg-turbo/libjpeg-turbo/commit/9120a247436e84c0b4eea828cb11e8f665fcde30]
27CVE: CVE-2020-35538
28Signed-off-by: Vijay Anusuri <vanusuri@mvista.com>
29---
30 ChangeLog.md | 7 +++++
31 jdapistd.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++------
32 jdmerge.c | 46 +++++++--------------------------
33 jdmerge.h | 47 ++++++++++++++++++++++++++++++++++
34 jdmrg565.c | 10 ++++----
35 jdmrgext.c | 6 ++---
36 6 files changed, 135 insertions(+), 53 deletions(-)
37 create mode 100644 jdmerge.h
38
39diff --git a/ChangeLog.md b/ChangeLog.md
40index 2ebfe71..19d18fa 100644
41--- a/ChangeLog.md
42+++ b/ChangeLog.md
43@@ -54,6 +54,13 @@ a 16-bit binary PGM file into an RGB image buffer.
44 generated when using the `tjLoadImage()` function to load a 16-bit binary PPM
45 file into an extended RGB image buffer.
46
47+2. Fixed segfaults or "Corrupt JPEG data: premature end of data segment" errors
48+in `jpeg_skip_scanlines()` that occurred when decompressing 4:2:2 or 4:2:0 JPEG
49+images using the merged (non-fancy) upsampling algorithms (that is, when
50+setting `cinfo.do_fancy_upsampling` to `FALSE`.) 2.0.0[6] was a similar fix,
51+but it did not cover all cases.
52+
53+
54 2.0.3
55 =====
56
57diff --git a/jdapistd.c b/jdapistd.c
58index 2c808fa..91da642 100644
59--- a/jdapistd.c
60+++ b/jdapistd.c
61@@ -4,7 +4,7 @@
62 * This file was part of the Independent JPEG Group's software:
63 * Copyright (C) 1994-1996, Thomas G. Lane.
64 * libjpeg-turbo Modifications:
65- * Copyright (C) 2010, 2015-2018, D. R. Commander.
66+ * Copyright (C) 2010, 2015-2018, 2020, D. R. Commander.
67 * Copyright (C) 2015, Google, Inc.
68 * For conditions of distribution and use, see the accompanying README.ijg
69 * file.
70@@ -21,6 +21,8 @@
71 #include "jinclude.h"
72 #include "jdmainct.h"
73 #include "jdcoefct.h"
74+#include "jdmaster.h"
75+#include "jdmerge.h"
76 #include "jdsample.h"
77 #include "jmemsys.h"
78
79@@ -304,6 +306,16 @@ noop_quantize(j_decompress_ptr cinfo, JSAMPARRAY input_buf,
80 }
81
82
83+/* Dummy postprocessing function used by jpeg_skip_scanlines() */
84+LOCAL(void)
85+noop_post_process (j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
86+ JDIMENSION *in_row_group_ctr,
87+ JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf,
88+ JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
89+{
90+}
91+
92+
93 /*
94 * In some cases, it is best to call jpeg_read_scanlines() and discard the
95 * output, rather than skipping the scanlines, because this allows us to
96@@ -316,11 +328,17 @@ LOCAL(void)
97 read_and_discard_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
98 {
99 JDIMENSION n;
100+ my_master_ptr master = (my_master_ptr)cinfo->master;
101 void (*color_convert) (j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
102 JDIMENSION input_row, JSAMPARRAY output_buf,
103 int num_rows) = NULL;
104 void (*color_quantize) (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
105 JSAMPARRAY output_buf, int num_rows) = NULL;
106+ void (*post_process_data) (j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
107+ JDIMENSION *in_row_group_ctr,
108+ JDIMENSION in_row_groups_avail,
109+ JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
110+ JDIMENSION out_rows_avail) = NULL;
111
112 if (cinfo->cconvert && cinfo->cconvert->color_convert) {
113 color_convert = cinfo->cconvert->color_convert;
114@@ -332,6 +350,12 @@ read_and_discard_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
115 cinfo->cquantize->color_quantize = noop_quantize;
116 }
117
118+ if (master->using_merged_upsample && cinfo->post &&
119+ cinfo->post->post_process_data) {
120+ post_process_data = cinfo->post->post_process_data;
121+ cinfo->post->post_process_data = noop_post_process;
122+ }
123+
124 for (n = 0; n < num_lines; n++)
125 jpeg_read_scanlines(cinfo, NULL, 1);
126
127@@ -340,6 +364,9 @@ read_and_discard_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
128
129 if (color_quantize)
130 cinfo->cquantize->color_quantize = color_quantize;
131+
132+ if (post_process_data)
133+ cinfo->post->post_process_data = post_process_data;
134 }
135
136
137@@ -382,7 +409,7 @@ jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
138 {
139 my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
140 my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
141- my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
142+ my_master_ptr master = (my_master_ptr)cinfo->master;
143 JDIMENSION i, x;
144 int y;
145 JDIMENSION lines_per_iMCU_row, lines_left_in_iMCU_row, lines_after_iMCU_row;
146@@ -445,8 +472,16 @@ jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
147 main_ptr->buffer_full = FALSE;
148 main_ptr->rowgroup_ctr = 0;
149 main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
150- upsample->next_row_out = cinfo->max_v_samp_factor;
151- upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
152+ if (master->using_merged_upsample) {
153+ my_merged_upsample_ptr upsample =
154+ (my_merged_upsample_ptr)cinfo->upsample;
155+ upsample->spare_full = FALSE;
156+ upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
157+ } else {
158+ my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
159+ upsample->next_row_out = cinfo->max_v_samp_factor;
160+ upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
161+ }
162 }
163
164 /* Skipping is much simpler when context rows are not required. */
165@@ -458,8 +493,16 @@ jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
166 cinfo->output_scanline += lines_left_in_iMCU_row;
167 main_ptr->buffer_full = FALSE;
168 main_ptr->rowgroup_ctr = 0;
169- upsample->next_row_out = cinfo->max_v_samp_factor;
170- upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
171+ if (master->using_merged_upsample) {
172+ my_merged_upsample_ptr upsample =
173+ (my_merged_upsample_ptr)cinfo->upsample;
174+ upsample->spare_full = FALSE;
175+ upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
176+ } else {
177+ my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
178+ upsample->next_row_out = cinfo->max_v_samp_factor;
179+ upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
180+ }
181 }
182 }
183
184@@ -494,7 +537,14 @@ jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
185 cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
186 increment_simple_rowgroup_ctr(cinfo, lines_to_read);
187 }
188- upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
189+ if (master->using_merged_upsample) {
190+ my_merged_upsample_ptr upsample =
191+ (my_merged_upsample_ptr)cinfo->upsample;
192+ upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
193+ } else {
194+ my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
195+ upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
196+ }
197 return num_lines;
198 }
199
200@@ -535,7 +585,13 @@ jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
201 * bit odd, since "rows_to_go" seems to be redundantly keeping track of
202 * output_scanline.
203 */
204- upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
205+ if (master->using_merged_upsample) {
206+ my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
207+ upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
208+ } else {
209+ my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
210+ upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
211+ }
212
213 /* Always skip the requested number of lines. */
214 return num_lines;
215diff --git a/jdmerge.c b/jdmerge.c
216index dff5a35..833ad67 100644
217--- a/jdmerge.c
218+++ b/jdmerge.c
219@@ -5,7 +5,7 @@
220 * Copyright (C) 1994-1996, Thomas G. Lane.
221 * libjpeg-turbo Modifications:
222 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
223- * Copyright (C) 2009, 2011, 2014-2015, D. R. Commander.
224+ * Copyright (C) 2009, 2011, 2014-2015, 2020, D. R. Commander.
225 * Copyright (C) 2013, Linaro Limited.
226 * For conditions of distribution and use, see the accompanying README.ijg
227 * file.
228@@ -40,41 +40,13 @@
229 #define JPEG_INTERNALS
230 #include "jinclude.h"
231 #include "jpeglib.h"
232+#include "jdmerge.h"
233 #include "jsimd.h"
234 #include "jconfigint.h"
235
236 #ifdef UPSAMPLE_MERGING_SUPPORTED
237
238
239-/* Private subobject */
240-
241-typedef struct {
242- struct jpeg_upsampler pub; /* public fields */
243-
244- /* Pointer to routine to do actual upsampling/conversion of one row group */
245- void (*upmethod) (j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
246- JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf);
247-
248- /* Private state for YCC->RGB conversion */
249- int *Cr_r_tab; /* => table for Cr to R conversion */
250- int *Cb_b_tab; /* => table for Cb to B conversion */
251- JLONG *Cr_g_tab; /* => table for Cr to G conversion */
252- JLONG *Cb_g_tab; /* => table for Cb to G conversion */
253-
254- /* For 2:1 vertical sampling, we produce two output rows at a time.
255- * We need a "spare" row buffer to hold the second output row if the
256- * application provides just a one-row buffer; we also use the spare
257- * to discard the dummy last row if the image height is odd.
258- */
259- JSAMPROW spare_row;
260- boolean spare_full; /* T if spare buffer is occupied */
261-
262- JDIMENSION out_row_width; /* samples per output row */
263- JDIMENSION rows_to_go; /* counts rows remaining in image */
264-} my_upsampler;
265-
266-typedef my_upsampler *my_upsample_ptr;
267-
268 #define SCALEBITS 16 /* speediest right-shift on some machines */
269 #define ONE_HALF ((JLONG)1 << (SCALEBITS - 1))
270 #define FIX(x) ((JLONG)((x) * (1L << SCALEBITS) + 0.5))
271@@ -189,7 +161,7 @@ typedef my_upsampler *my_upsample_ptr;
272 LOCAL(void)
273 build_ycc_rgb_table(j_decompress_ptr cinfo)
274 {
275- my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
276+ my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
277 int i;
278 JLONG x;
279 SHIFT_TEMPS
280@@ -232,7 +204,7 @@ build_ycc_rgb_table(j_decompress_ptr cinfo)
281 METHODDEF(void)
282 start_pass_merged_upsample(j_decompress_ptr cinfo)
283 {
284- my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
285+ my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
286
287 /* Mark the spare buffer empty */
288 upsample->spare_full = FALSE;
289@@ -254,7 +226,7 @@ merged_2v_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
290 JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
291 /* 2:1 vertical sampling case: may need a spare row. */
292 {
293- my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
294+ my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
295 JSAMPROW work_ptrs[2];
296 JDIMENSION num_rows; /* number of rows returned to caller */
297
298@@ -305,7 +277,7 @@ merged_1v_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
299 JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
300 /* 1:1 vertical sampling case: much easier, never need a spare row. */
301 {
302- my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
303+ my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
304
305 /* Just do the upsampling. */
306 (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
307@@ -566,11 +538,11 @@ h2v2_merged_upsample_565D(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
308 GLOBAL(void)
309 jinit_merged_upsampler(j_decompress_ptr cinfo)
310 {
311- my_upsample_ptr upsample;
312+ my_merged_upsample_ptr upsample;
313
314- upsample = (my_upsample_ptr)
315+ upsample = (my_merged_upsample_ptr)
316 (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
317- sizeof(my_upsampler));
318+ sizeof(my_merged_upsampler));
319 cinfo->upsample = (struct jpeg_upsampler *)upsample;
320 upsample->pub.start_pass = start_pass_merged_upsample;
321 upsample->pub.need_context_rows = FALSE;
322diff --git a/jdmerge.h b/jdmerge.h
323new file mode 100644
324index 0000000..b583396
325--- /dev/null
326+++ b/jdmerge.h
327@@ -0,0 +1,47 @@
328+/*
329+ * jdmerge.h
330+ *
331+ * This file was part of the Independent JPEG Group's software:
332+ * Copyright (C) 1994-1996, Thomas G. Lane.
333+ * libjpeg-turbo Modifications:
334+ * Copyright (C) 2020, D. R. Commander.
335+ * For conditions of distribution and use, see the accompanying README.ijg
336+ * file.
337+ */
338+
339+#define JPEG_INTERNALS
340+#include "jpeglib.h"
341+
342+#ifdef UPSAMPLE_MERGING_SUPPORTED
343+
344+
345+/* Private subobject */
346+
347+typedef struct {
348+ struct jpeg_upsampler pub; /* public fields */
349+
350+ /* Pointer to routine to do actual upsampling/conversion of one row group */
351+ void (*upmethod) (j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
352+ JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf);
353+
354+ /* Private state for YCC->RGB conversion */
355+ int *Cr_r_tab; /* => table for Cr to R conversion */
356+ int *Cb_b_tab; /* => table for Cb to B conversion */
357+ JLONG *Cr_g_tab; /* => table for Cr to G conversion */
358+ JLONG *Cb_g_tab; /* => table for Cb to G conversion */
359+
360+ /* For 2:1 vertical sampling, we produce two output rows at a time.
361+ * We need a "spare" row buffer to hold the second output row if the
362+ * application provides just a one-row buffer; we also use the spare
363+ * to discard the dummy last row if the image height is odd.
364+ */
365+ JSAMPROW spare_row;
366+ boolean spare_full; /* T if spare buffer is occupied */
367+
368+ JDIMENSION out_row_width; /* samples per output row */
369+ JDIMENSION rows_to_go; /* counts rows remaining in image */
370+} my_merged_upsampler;
371+
372+typedef my_merged_upsampler *my_merged_upsample_ptr;
373+
374+#endif /* UPSAMPLE_MERGING_SUPPORTED */
375diff --git a/jdmrg565.c b/jdmrg565.c
376index 1b87e37..53f1e16 100644
377--- a/jdmrg565.c
378+++ b/jdmrg565.c
379@@ -5,7 +5,7 @@
380 * Copyright (C) 1994-1996, Thomas G. Lane.
381 * libjpeg-turbo Modifications:
382 * Copyright (C) 2013, Linaro Limited.
383- * Copyright (C) 2014-2015, 2018, D. R. Commander.
384+ * Copyright (C) 2014-2015, 2018, 2020, D. R. Commander.
385 * For conditions of distribution and use, see the accompanying README.ijg
386 * file.
387 *
388@@ -19,7 +19,7 @@ h2v1_merged_upsample_565_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
389 JDIMENSION in_row_group_ctr,
390 JSAMPARRAY output_buf)
391 {
392- my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
393+ my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
394 register int y, cred, cgreen, cblue;
395 int cb, cr;
396 register JSAMPROW outptr;
397@@ -90,7 +90,7 @@ h2v1_merged_upsample_565D_internal(j_decompress_ptr cinfo,
398 JDIMENSION in_row_group_ctr,
399 JSAMPARRAY output_buf)
400 {
401- my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
402+ my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
403 register int y, cred, cgreen, cblue;
404 int cb, cr;
405 register JSAMPROW outptr;
406@@ -163,7 +163,7 @@ h2v2_merged_upsample_565_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
407 JDIMENSION in_row_group_ctr,
408 JSAMPARRAY output_buf)
409 {
410- my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
411+ my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
412 register int y, cred, cgreen, cblue;
413 int cb, cr;
414 register JSAMPROW outptr0, outptr1;
415@@ -259,7 +259,7 @@ h2v2_merged_upsample_565D_internal(j_decompress_ptr cinfo,
416 JDIMENSION in_row_group_ctr,
417 JSAMPARRAY output_buf)
418 {
419- my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
420+ my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
421 register int y, cred, cgreen, cblue;
422 int cb, cr;
423 register JSAMPROW outptr0, outptr1;
424diff --git a/jdmrgext.c b/jdmrgext.c
425index b1c27df..c9a44d8 100644
426--- a/jdmrgext.c
427+++ b/jdmrgext.c
428@@ -4,7 +4,7 @@
429 * This file was part of the Independent JPEG Group's software:
430 * Copyright (C) 1994-1996, Thomas G. Lane.
431 * libjpeg-turbo Modifications:
432- * Copyright (C) 2011, 2015, D. R. Commander.
433+ * Copyright (C) 2011, 2015, 2020, D. R. Commander.
434 * For conditions of distribution and use, see the accompanying README.ijg
435 * file.
436 *
437@@ -25,7 +25,7 @@ h2v1_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
438 JDIMENSION in_row_group_ctr,
439 JSAMPARRAY output_buf)
440 {
441- my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
442+ my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
443 register int y, cred, cgreen, cblue;
444 int cb, cr;
445 register JSAMPROW outptr;
446@@ -97,7 +97,7 @@ h2v2_merged_upsample_internal(j_decompress_ptr cinfo, JSAMPIMAGE input_buf,
447 JDIMENSION in_row_group_ctr,
448 JSAMPARRAY output_buf)
449 {
450- my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
451+ my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
452 register int y, cred, cgreen, cblue;
453 int cb, cr;
454 register JSAMPROW outptr0, outptr1;
455--
4562.25.1
457