Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Side by Side Diff: third_party/libopenjpeg20/jp2.c

Issue 1992893003: Fix a memory leak in opj_jp2_read_ihdr(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/libopenjpeg20/README.pdfium ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * The copyright in this software is being made available under the 2-clauses 2 * The copyright in this software is being made available under the 2-clauses
3 * BSD License, included below. This software may be subject to other third 3 * BSD License, included below. This software may be subject to other third
4 * party and contributor rights, including patent rights, and no such rights 4 * party and contributor rights, including patent rights, and no such rights
5 * are granted under this license. 5 * are granted under this license.
6 * 6 *
7 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium 7 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
8 * Copyright (c) 2002-2014, Professor Benoit Macq 8 * Copyright (c) 2002-2014, Professor Benoit Macq
9 * Copyright (c) 2001-2003, David Janssens 9 * Copyright (c) 2001-2003, David Janssens
10 * Copyright (c) 2002-2003, Yannick Verschueren 10 * Copyright (c) 2002-2003, Yannick Verschueren
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 } 554 }
555 555
556 opj_read_bytes(p_image_header_data,&(jp2->h),4); /* HEIGHT */ 556 opj_read_bytes(p_image_header_data,&(jp2->h),4); /* HEIGHT */
557 p_image_header_data += 4; 557 p_image_header_data += 4;
558 opj_read_bytes(p_image_header_data,&(jp2->w),4); /* WIDTH */ 558 opj_read_bytes(p_image_header_data,&(jp2->w),4); /* WIDTH */
559 p_image_header_data += 4; 559 p_image_header_data += 4;
560 opj_read_bytes(p_image_header_data,&(jp2->numcomps),2); /* NC */ 560 opj_read_bytes(p_image_header_data,&(jp2->numcomps),2); /* NC */
561 p_image_header_data += 2; 561 p_image_header_data += 2;
562 562
563 /* allocate memory for components */ 563 /* allocate memory for components */
564 opj_free(jp2->comps);
564 jp2->comps = (opj_jp2_comps_t*) opj_calloc(jp2->numcomps, sizeof(opj_jp2 _comps_t)); 565 jp2->comps = (opj_jp2_comps_t*) opj_calloc(jp2->numcomps, sizeof(opj_jp2 _comps_t));
565 if (jp2->comps == 0) { 566 if (jp2->comps == 0) {
566 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle image header (ihdr)\n"); 567 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle image header (ihdr)\n");
567 return OPJ_FALSE; 568 return OPJ_FALSE;
568 } 569 }
569 570
570 opj_read_bytes(p_image_header_data,&(jp2->bpc),1); /* BPC */ 571 opj_read_bytes(p_image_header_data,&(jp2->bpc),1); /* BPC */
571 ++ p_image_header_data; 572 ++ p_image_header_data;
572 573
573 opj_read_bytes(p_image_header_data,&(jp2->C),1); /* C */ 574 opj_read_bytes(p_image_header_data,&(jp2->C),1); /* C */
(...skipping 1177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1751 /* JP2 decoder interface */ 1752 /* JP2 decoder interface */
1752 /* ----------------------------------------------------------------------- */ 1753 /* ----------------------------------------------------------------------- */
1753 1754
1754 void opj_jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters) 1755 void opj_jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters)
1755 { 1756 {
1756 /* setup the J2K codec */ 1757 /* setup the J2K codec */
1757 opj_j2k_setup_decoder(jp2->j2k, parameters); 1758 opj_j2k_setup_decoder(jp2->j2k, parameters);
1758 1759
1759 /* further JP2 initializations go here */ 1760 /* further JP2 initializations go here */
1760 jp2->color.jp2_has_colr = 0; 1761 jp2->color.jp2_has_colr = 0;
1762 jp2->comps = NULL;
1761 jp2->ignore_pclr_cmap_cdef = parameters->flags & OPJ_DPARAMETERS_IGNORE_PCLR _CMAP_CDEF_FLAG; 1763 jp2->ignore_pclr_cmap_cdef = parameters->flags & OPJ_DPARAMETERS_IGNORE_PCLR _CMAP_CDEF_FLAG;
1762 } 1764 }
1763 1765
1764 /* ----------------------------------------------------------------------- */ 1766 /* ----------------------------------------------------------------------- */
1765 /* JP2 encoder interface */ 1767 /* JP2 encoder interface */
1766 /* ----------------------------------------------------------------------- */ 1768 /* ----------------------------------------------------------------------- */
1767 1769
1768 OPJ_BOOL opj_jp2_setup_encoder( opj_jp2_t *jp2, 1770 OPJ_BOOL opj_jp2_setup_encoder( opj_jp2_t *jp2,
1769 opj_cparameters_t *parameters, 1771 opj_cparameters_t *parameters,
1770 opj_image_t *image, 1772 opj_image_t *image,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1808 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setu p the JP2 encoder\n"); 1810 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setu p the JP2 encoder\n");
1809 return OPJ_FALSE; 1811 return OPJ_FALSE;
1810 } 1812 }
1811 jp2->cl[0] = JP2_JP2; /* CL0 : JP2 */ 1813 jp2->cl[0] = JP2_JP2; /* CL0 : JP2 */
1812 1814
1813 /* Image Header box */ 1815 /* Image Header box */
1814 1816
1815 jp2->numcomps = image->numcomps; /* NC */ 1817 jp2->numcomps = image->numcomps; /* NC */
1816 jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp 2_comps_t)); 1818 jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp 2_comps_t));
1817 if (!jp2->comps) { 1819 if (!jp2->comps) {
1818 jp2->comps = NULL;
1819 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setu p the JP2 encoder\n"); 1820 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setu p the JP2 encoder\n");
1820 /* Memory of jp2->cl will be freed by opj_jp2_destroy */ 1821 /* Memory of jp2->cl will be freed by opj_jp2_destroy */
1821 return OPJ_FALSE; 1822 return OPJ_FALSE;
1822 } 1823 }
1823 1824
1824 jp2->h = image->y1 - image->y0; /* HEIGHT */ 1825 jp2->h = image->y1 - image->y0; /* HEIGHT */
1825 jp2->w = image->x1 - image->x0; /* WIDTH */ 1826 jp2->w = image->x1 - image->x0; /* WIDTH */
1826 /* BPC */ 1827 /* BPC */
1827 depth_0 = image->comps[0].prec - 1; 1828 depth_0 = image->comps[0].prec - 1;
1828 sign = image->comps[0].sgnd; 1829 sign = image->comps[0].sgnd;
(...skipping 1324 matching lines...) Expand 10 before | Expand all | Expand 10 after
3153 len = opj_stream_tell(cio)-lenp; 3154 len = opj_stream_tell(cio)-lenp;
3154 opj_stream_skip(cio, lenp, p_manager); 3155 opj_stream_skip(cio, lenp, p_manager);
3155 opj_write_bytes(l_data_header,len,4);/* L */ 3156 opj_write_bytes(l_data_header,len,4);/* L */
3156 opj_stream_write_data(cio,l_data_header,4,p_manager); 3157 opj_stream_write_data(cio,l_data_header,4,p_manager);
3157 opj_stream_seek(cio, lenp+len,p_manager); 3158 opj_stream_seek(cio, lenp+len,p_manager);
3158 3159
3159 return len; 3160 return len;
3160 } 3161 }
3161 #endif 3162 #endif
3162 #endif /* USE_JPIP */ 3163 #endif /* USE_JPIP */
OLDNEW
« no previous file with comments | « third_party/libopenjpeg20/README.pdfium ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698