netpbm-security-code.patch 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683
  1. diff -up netpbm-10.58.01/analyzer/pgmtexture.c.security-code netpbm-10.58.01/analyzer/pgmtexture.c
  2. --- netpbm-10.58.01/analyzer/pgmtexture.c.security-code 2012-04-09 15:31:32.000000000 +0200
  3. +++ netpbm-10.58.01/analyzer/pgmtexture.c 2012-04-09 15:40:03.183620040 +0200
  4. @@ -97,7 +97,7 @@ vector(unsigned int const nl,
  5. float * v;
  6. assert(nh >= nl);
  7. -
  8. + overflow_add(nh - nl, 1);
  9. MALLOCARRAY(v, (unsigned) (nh - nl + 1));
  10. if (v == NULL)
  11. @@ -129,6 +129,7 @@ matrix (unsigned int const nrl,
  12. assert(nrh >= nrl);
  13. /* allocate pointers to rows */
  14. + overflow_add(nrh - nrl, 1);
  15. MALLOCARRAY(m, (unsigned) (nrh - nrl + 1));
  16. if (m == NULL)
  17. pm_error("Unable to allocate memory for a matrix.");
  18. @@ -136,7 +137,7 @@ matrix (unsigned int const nrl,
  19. m -= ncl;
  20. assert (nch >= ncl);
  21. -
  22. + overflow_add(nch - ncl, 1);
  23. /* allocate rows and set pointers to them */
  24. for (i = nrl; i <= nrh; ++i) {
  25. MALLOCARRAY(m[i], (unsigned) (nch - ncl + 1));
  26. diff -up netpbm-10.58.01/converter/other/gemtopnm.c.security-code netpbm-10.58.01/converter/other/gemtopnm.c
  27. --- netpbm-10.58.01/converter/other/gemtopnm.c.security-code 2012-04-09 15:31:42.000000000 +0200
  28. +++ netpbm-10.58.01/converter/other/gemtopnm.c 2012-04-09 15:40:03.183620040 +0200
  29. @@ -106,6 +106,7 @@ main(argc, argv)
  30. pnm_writepnminit( stdout, cols, rows, MAXVAL, type, 0 );
  31. + overflow_add(cols, padright);
  32. {
  33. /* allocate input row data structure */
  34. int plane;
  35. diff -up netpbm-10.58.01/converter/other/jpegtopnm.c.security-code netpbm-10.58.01/converter/other/jpegtopnm.c
  36. --- netpbm-10.58.01/converter/other/jpegtopnm.c.security-code 2012-04-09 15:31:40.000000000 +0200
  37. +++ netpbm-10.58.01/converter/other/jpegtopnm.c 2012-04-09 15:40:03.184620028 +0200
  38. @@ -861,6 +861,8 @@ convertImage(FILE *
  39. /* Calculate output image dimensions so we can allocate space */
  40. jpeg_calc_output_dimensions(cinfoP);
  41. + overflow2(cinfoP->output_width, cinfoP->output_components);
  42. +
  43. /* Start decompressor */
  44. jpeg_start_decompress(cinfoP);
  45. diff -up netpbm-10.58.01/converter/other/pbmtopgm.c.security-code netpbm-10.58.01/converter/other/pbmtopgm.c
  46. --- netpbm-10.58.01/converter/other/pbmtopgm.c.security-code 2012-04-09 15:31:42.000000000 +0200
  47. +++ netpbm-10.58.01/converter/other/pbmtopgm.c 2012-04-09 15:40:03.184620028 +0200
  48. @@ -47,6 +47,7 @@ main(int argc, char *argv[]) {
  49. "than the image height (%u rows)", height, rows);
  50. outrow = pgm_allocrow(cols) ;
  51. + overflow2(width, height);
  52. maxval = MIN(PGM_OVERALLMAXVAL, width*height);
  53. pgm_writepgminit(stdout, cols, rows, maxval, 0) ;
  54. diff -up netpbm-10.58.01/converter/other/pnmtoddif.c.security-code netpbm-10.58.01/converter/other/pnmtoddif.c
  55. --- netpbm-10.58.01/converter/other/pnmtoddif.c.security-code 2012-04-09 15:31:42.000000000 +0200
  56. +++ netpbm-10.58.01/converter/other/pnmtoddif.c 2012-04-09 15:40:03.185620015 +0200
  57. @@ -632,6 +632,7 @@ main(int argc, char *argv[]) {
  58. switch (PNM_FORMAT_TYPE(format)) {
  59. case PBM_TYPE:
  60. ip.bits_per_pixel = 1;
  61. + overflow_add(cols, 7);
  62. ip.bytes_per_line = (cols + 7) / 8;
  63. ip.spectral = 2;
  64. ip.components = 1;
  65. @@ -647,6 +648,7 @@ main(int argc, char *argv[]) {
  66. ip.polarity = 2;
  67. break;
  68. case PPM_TYPE:
  69. + overflow2(cols, 3);
  70. ip.bytes_per_line = 3 * cols;
  71. ip.bits_per_pixel = 24;
  72. ip.spectral = 5;
  73. diff -up netpbm-10.58.01/converter/other/pnmtojpeg.c.security-code netpbm-10.58.01/converter/other/pnmtojpeg.c
  74. --- netpbm-10.58.01/converter/other/pnmtojpeg.c.security-code 2012-04-09 15:31:39.000000000 +0200
  75. +++ netpbm-10.58.01/converter/other/pnmtojpeg.c 2012-04-09 15:40:03.186620002 +0200
  76. @@ -605,7 +605,11 @@ read_scan_script(j_compress_ptr const ci
  77. want JPOOL_PERMANENT.
  78. */
  79. const unsigned int scan_info_size = nscans * sizeof(jpeg_scan_info);
  80. - jpeg_scan_info * const scan_info =
  81. + const jpeg_scan_info * scan_info;
  82. +
  83. + overflow2(nscans, sizeof(jpeg_scan_info));
  84. +
  85. + scan_info =
  86. (jpeg_scan_info *)
  87. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  88. scan_info_size);
  89. @@ -937,6 +941,8 @@ compute_rescaling_array(JSAMPLE ** const
  90. const long half_maxval = maxval / 2;
  91. long val;
  92. + overflow_add(maxval, 1);
  93. + overflow2(maxval+1, sizeof(JSAMPLE));
  94. *rescale_p = (JSAMPLE *)
  95. (cinfo.mem->alloc_small) ((j_common_ptr) &cinfo, JPOOL_IMAGE,
  96. (size_t) (((long) maxval + 1L) *
  97. @@ -1015,6 +1021,7 @@ convert_scanlines(struct jpeg_compress_s
  98. */
  99. /* Allocate the libpnm output and compressor input buffers */
  100. + overflow2(cinfo_p->image_width, cinfo_p->input_components);
  101. buffer = (*cinfo_p->mem->alloc_sarray)
  102. ((j_common_ptr) cinfo_p, JPOOL_IMAGE,
  103. (unsigned int) cinfo_p->image_width * cinfo_p->input_components,
  104. diff -up netpbm-10.58.01/converter/other/pnmtops.c.security-code netpbm-10.58.01/converter/other/pnmtops.c
  105. --- netpbm-10.58.01/converter/other/pnmtops.c.security-code 2012-04-09 15:31:40.000000000 +0200
  106. +++ netpbm-10.58.01/converter/other/pnmtops.c 2012-04-09 15:40:03.187619989 +0200
  107. @@ -256,17 +256,21 @@ parseCommandLine(int argc, const char **
  108. validateCompDimension(width, 72, "-width value");
  109. validateCompDimension(height, 72, "-height value");
  110. + overflow2(width, 72);
  111. cmdlineP->width = width * 72;
  112. + overflow2(height, 72);
  113. cmdlineP->height = height * 72;
  114. if (imagewidthSpec) {
  115. validateCompDimension(imagewidth, 72, "-imagewidth value");
  116. + overflow2(imagewidth, 72);
  117. cmdlineP->imagewidth = imagewidth * 72;
  118. }
  119. else
  120. cmdlineP->imagewidth = 0;
  121. if (imageheightSpec) {
  122. - validateCompDimension(imagewidth, 72, "-imageheight value");
  123. + validateCompDimension(imageheight, 72, "-imageheight value");
  124. + overflow2(imageheight, 72);
  125. cmdlineP->imageheight = imageheight * 72;
  126. }
  127. else
  128. diff -up netpbm-10.58.01/converter/other/pnmtorle.c.security-code netpbm-10.58.01/converter/other/pnmtorle.c
  129. --- netpbm-10.58.01/converter/other/pnmtorle.c.security-code 2012-04-09 15:31:42.000000000 +0200
  130. +++ netpbm-10.58.01/converter/other/pnmtorle.c 2012-04-09 15:40:03.188619976 +0200
  131. @@ -19,6 +19,8 @@
  132. * If you modify this software, you should include a notice giving the
  133. * name of the person performing the modification, the date of modification,
  134. * and the reason for such modification.
  135. + *
  136. + * 2002-12-19: Fix maths wrapping bugs. Alan Cox <alan@redhat.com>
  137. */
  138. /*
  139. * pnmtorle - A program which will convert pbmplus (ppm or pgm) images
  140. diff -up netpbm-10.58.01/converter/other/pnmtosgi.c.security-code netpbm-10.58.01/converter/other/pnmtosgi.c
  141. --- netpbm-10.58.01/converter/other/pnmtosgi.c.security-code 2012-04-09 15:31:42.000000000 +0200
  142. +++ netpbm-10.58.01/converter/other/pnmtosgi.c 2012-04-09 15:40:03.188619976 +0200
  143. @@ -254,6 +254,7 @@ build_channels(FILE * const ifp, int con
  144. #endif
  145. if( storage != STORAGE_VERBATIM ) {
  146. + overflow2(channels, rows);
  147. MALLOCARRAY_NOFAIL(table, channels * rows);
  148. MALLOCARRAY_NOFAIL(rletemp, WORSTCOMPR(cols));
  149. }
  150. @@ -306,6 +307,8 @@ compress(ScanElem * temp,
  151. break;
  152. case STORAGE_RLE:
  153. tabrow = chan_no * rows + row;
  154. + overflow2(chan_no, rows);
  155. + overflow_add(chan_no* rows, row);
  156. len = rle_compress(temp, cols); /* writes result into rletemp */
  157. channel[chan_no][row].length = len;
  158. MALLOCARRAY(p, len);
  159. diff -up netpbm-10.58.01/converter/other/rletopnm.c.security-code netpbm-10.58.01/converter/other/rletopnm.c
  160. --- netpbm-10.58.01/converter/other/rletopnm.c.security-code 2012-04-09 15:31:42.000000000 +0200
  161. +++ netpbm-10.58.01/converter/other/rletopnm.c 2012-04-09 15:40:03.189619963 +0200
  162. @@ -19,6 +19,8 @@
  163. * If you modify this software, you should include a notice giving the
  164. * name of the person performing the modification, the date of modification,
  165. * and the reason for such modification.
  166. + *
  167. + * 2002-12-19: Fix maths wrapping bugs. Alan Cox <alan@redhat.com>
  168. */
  169. /*
  170. * rletopnm - A conversion program to convert from Utah's "rle" image format
  171. diff -up netpbm-10.58.01/converter/other/sgitopnm.c.security-code netpbm-10.58.01/converter/other/sgitopnm.c
  172. --- netpbm-10.58.01/converter/other/sgitopnm.c.security-code 2012-04-09 15:31:42.000000000 +0200
  173. +++ netpbm-10.58.01/converter/other/sgitopnm.c 2012-04-09 15:40:03.189619963 +0200
  174. @@ -359,10 +359,14 @@ readChannels(FILE * const ifP,
  175. MALLOCARRAY_NOFAIL(image, head->ysize);
  176. } else {
  177. maxchannel = MIN(3, head->zsize);
  178. + overflow2(head->ysize, maxchannel);
  179. MALLOCARRAY_NOFAIL(image, head->ysize * maxchannel);
  180. }
  181. - if (table)
  182. + if (table) {
  183. + overflow2(head->xsize, 2);
  184. + overflow_add(head->xsize*2, 2);
  185. MALLOCARRAY_NOFAIL(temp, WORSTCOMPR(head->xsize));
  186. + }
  187. for (channel = 0; channel < maxchannel; ++channel) {
  188. unsigned int row;
  189. diff -up netpbm-10.58.01/converter/other/sirtopnm.c.security-code netpbm-10.58.01/converter/other/sirtopnm.c
  190. --- netpbm-10.58.01/converter/other/sirtopnm.c.security-code 2012-04-09 15:31:42.000000000 +0200
  191. +++ netpbm-10.58.01/converter/other/sirtopnm.c 2012-04-09 15:40:03.190619951 +0200
  192. @@ -69,6 +69,7 @@ char* argv[];
  193. }
  194. break;
  195. case PPM_TYPE:
  196. + overflow3(cols, rows, 3);
  197. picsize = cols * rows * 3;
  198. planesize = cols * rows;
  199. if ( !( sirarray = (unsigned char*) malloc( picsize ) ) )
  200. diff -up netpbm-10.58.01/converter/other/tifftopnm.c.security-code netpbm-10.58.01/converter/other/tifftopnm.c
  201. --- netpbm-10.58.01/converter/other/tifftopnm.c.security-code 2012-04-09 15:31:42.000000000 +0200
  202. +++ netpbm-10.58.01/converter/other/tifftopnm.c 2012-04-09 15:40:03.191619939 +0200
  203. @@ -1279,7 +1279,9 @@ convertRasterByRows(pnmOut * const
  204. if (scanbuf == NULL)
  205. pm_error("can't allocate memory for scanline buffer");
  206. - MALLOCARRAY(samplebuf, cols * spp);
  207. + /* samplebuf is unsigned int * !!! */
  208. + samplebuf = (unsigned int *) malloc3(cols , sizeof(unsigned int) , spp);
  209. +
  210. if (samplebuf == NULL)
  211. pm_error("can't allocate memory for row buffer");
  212. diff -up netpbm-10.58.01/converter/other/xwdtopnm.c.security-code netpbm-10.58.01/converter/other/xwdtopnm.c
  213. --- netpbm-10.58.01/converter/other/xwdtopnm.c.security-code 2012-04-09 15:31:40.000000000 +0200
  214. +++ netpbm-10.58.01/converter/other/xwdtopnm.c 2012-04-09 15:40:03.192619927 +0200
  215. @@ -209,6 +209,10 @@ processX10Header(X10WDFileHeader * cons
  216. *colorsP = pnm_allocrow(2);
  217. PNM_ASSIGN1((*colorsP)[0], 0);
  218. PNM_ASSIGN1((*colorsP)[1], *maxvalP);
  219. + overflow_add(h10P->pixmap_width, 15);
  220. + if(h10P->pixmap_width < 0)
  221. + pm_error("assert: negative width");
  222. + overflow2((((h10P->pixmap_width + 15) / 16) * 16 - h10P->pixmap_width), 8);
  223. *padrightP =
  224. (((h10P->pixmap_width + 15) / 16) * 16 - h10P->pixmap_width) * 8;
  225. *bits_per_itemP = 16;
  226. @@ -634,6 +638,7 @@ processX11Header(X11WDFileHeader * cons
  227. *colsP = h11FixedP->pixmap_width;
  228. *rowsP = h11FixedP->pixmap_height;
  229. + overflow2(h11FixedP->bytes_per_line, 8);
  230. *padrightP =
  231. h11FixedP->bytes_per_line * 8 -
  232. h11FixedP->pixmap_width * h11FixedP->bits_per_pixel;
  233. diff -up netpbm-10.58.01/converter/pbm/mdatopbm.c.security-code netpbm-10.58.01/converter/pbm/mdatopbm.c
  234. --- netpbm-10.58.01/converter/pbm/mdatopbm.c.security-code 2012-04-09 15:31:45.000000000 +0200
  235. +++ netpbm-10.58.01/converter/pbm/mdatopbm.c 2012-04-09 15:40:03.192619927 +0200
  236. @@ -245,10 +245,13 @@ main(int argc, char **argv) {
  237. pm_readlittleshort(infile, &yy); nInCols = yy;
  238. }
  239. + overflow2(nOutCols, 8);
  240. nOutCols = 8 * nInCols;
  241. nOutRows = nInRows;
  242. - if (bScale)
  243. + if (bScale) {
  244. + overflow2(nOutRows, 2);
  245. nOutRows *= 2;
  246. + }
  247. data = pbm_allocarray(nOutCols, nOutRows);
  248. diff -up netpbm-10.58.01/converter/pbm/mgrtopbm.c.security-code netpbm-10.58.01/converter/pbm/mgrtopbm.c
  249. --- netpbm-10.58.01/converter/pbm/mgrtopbm.c.security-code 2012-04-09 15:31:45.000000000 +0200
  250. +++ netpbm-10.58.01/converter/pbm/mgrtopbm.c 2012-04-09 15:40:03.193619915 +0200
  251. @@ -65,6 +65,8 @@ readMgrHeader(FILE * const ifP,
  252. if (head.h_high < ' ' || head.l_high < ' ')
  253. pm_error("Invalid width field in MGR header");
  254. + overflow_add(*colsP, pad);
  255. +
  256. *colsP = (((int)head.h_wide - ' ') << 6) + ((int)head.l_wide - ' ');
  257. *rowsP = (((int)head.h_high - ' ') << 6) + ((int) head.l_high - ' ');
  258. *padrightP = ( ( *colsP + pad - 1 ) / pad ) * pad - *colsP;
  259. diff -up netpbm-10.58.01/converter/pbm/pbmtogem.c.security-code netpbm-10.58.01/converter/pbm/pbmtogem.c
  260. --- netpbm-10.58.01/converter/pbm/pbmtogem.c.security-code 2012-04-09 15:31:45.000000000 +0200
  261. +++ netpbm-10.58.01/converter/pbm/pbmtogem.c 2012-04-09 15:40:03.193619915 +0200
  262. @@ -79,6 +79,7 @@ putinit (int const rows, int const cols)
  263. bitsperitem = 0;
  264. bitshift = 7;
  265. outcol = 0;
  266. + overflow_add(cols, 7);
  267. outmax = (cols + 7) / 8;
  268. outrow = (unsigned char *) pm_allocrow (outmax, sizeof (unsigned char));
  269. lastrow = (unsigned char *) pm_allocrow (outmax, sizeof (unsigned char));
  270. diff -up netpbm-10.58.01/converter/pbm/pbmtogo.c.security-code netpbm-10.58.01/converter/pbm/pbmtogo.c
  271. --- netpbm-10.58.01/converter/pbm/pbmtogo.c.security-code 2012-04-09 15:31:45.000000000 +0200
  272. +++ netpbm-10.58.01/converter/pbm/pbmtogo.c 2012-04-09 15:40:03.193619915 +0200
  273. @@ -158,6 +158,7 @@ main(int argc,
  274. bitrow = pbm_allocrow(cols);
  275. /* Round cols up to the nearest multiple of 8. */
  276. + overflow_add(cols, 7);
  277. rucols = ( cols + 7 ) / 8;
  278. bytesperrow = rucols; /* GraphOn uses bytes */
  279. rucols = rucols * 8;
  280. diff -up netpbm-10.58.01/converter/pbm/pbmtolj.c.security-code netpbm-10.58.01/converter/pbm/pbmtolj.c
  281. --- netpbm-10.58.01/converter/pbm/pbmtolj.c.security-code 2012-04-09 15:31:45.000000000 +0200
  282. +++ netpbm-10.58.01/converter/pbm/pbmtolj.c 2012-04-09 15:40:03.194619902 +0200
  283. @@ -120,7 +120,11 @@ parseCommandLine(int argc, char ** argv,
  284. static void
  285. allocateBuffers(unsigned int const cols) {
  286. + overflow_add(cols, 8);
  287. rowBufferSize = (cols + 7) / 8;
  288. + overflow_add(rowBufferSize, 128);
  289. + overflow_add(rowBufferSize, rowBufferSize+128);
  290. + overflow_add(rowBufferSize+10, rowBufferSize/8);
  291. packBufferSize = rowBufferSize + (rowBufferSize + 127) / 128 + 1;
  292. deltaBufferSize = rowBufferSize + rowBufferSize / 8 + 10;
  293. diff -up netpbm-10.58.01/converter/pbm/pbmtomacp.c.security-code netpbm-10.58.01/converter/pbm/pbmtomacp.c
  294. --- netpbm-10.58.01/converter/pbm/pbmtomacp.c.security-code 2012-04-09 15:31:45.000000000 +0200
  295. +++ netpbm-10.58.01/converter/pbm/pbmtomacp.c 2012-04-09 15:40:03.195619889 +0200
  296. @@ -101,6 +101,7 @@ char *argv[];
  297. if( !lflg )
  298. left = 0;
  299. + overflow_add(left, MAX_COLS - 1);
  300. if( rflg )
  301. { if( right - left >= MAX_COLS )
  302. right = left + MAX_COLS - 1;
  303. @@ -111,6 +112,8 @@ char *argv[];
  304. if( !tflg )
  305. top = 0;
  306. + overflow_add(top, MAX_LINES - 1);
  307. +
  308. if( bflg )
  309. { if( bottom - top >= MAX_LINES )
  310. bottom = top + MAX_LINES - 1;
  311. diff -up netpbm-10.58.01/converter/pbm/pbmtomda.c.security-code netpbm-10.58.01/converter/pbm/pbmtomda.c
  312. --- netpbm-10.58.01/converter/pbm/pbmtomda.c.security-code 2012-04-09 15:31:45.000000000 +0200
  313. +++ netpbm-10.58.01/converter/pbm/pbmtomda.c 2012-04-09 15:40:03.195619889 +0200
  314. @@ -179,6 +179,7 @@ int main(int argc, char **argv)
  315. nOutRowsUnrounded = bScale ? nInRows/2 : nInRows;
  316. + overflow_add(nOutRowsUnrounded, 3);
  317. nOutRows = ((nOutRowsUnrounded + 3) / 4) * 4;
  318. /* MDA wants rows a multiple of 4 */
  319. nOutCols = nInCols / 8;
  320. diff -up netpbm-10.58.01/converter/pbm/pbmtoppa/pbm.c.security-code netpbm-10.58.01/converter/pbm/pbmtoppa/pbm.c
  321. --- netpbm-10.58.01/converter/pbm/pbmtoppa/pbm.c.security-code 2012-04-09 15:31:45.000000000 +0200
  322. +++ netpbm-10.58.01/converter/pbm/pbmtoppa/pbm.c 2012-04-09 15:40:03.195619889 +0200
  323. @@ -105,6 +105,7 @@ int pbm_readline(pbm_stat* pbm,unsigned
  324. return 0;
  325. case P4:
  326. + overflow_add(pbm->width, 7);
  327. tmp=(pbm->width+7)/8;
  328. tmp2=fread(data,1,tmp,pbm->fptr);
  329. if(tmp2 == tmp)
  330. @@ -129,7 +130,8 @@ void pbm_unreadline (pbm_stat *pbm, void
  331. return;
  332. pbm->unread = 1;
  333. - pbm->revdata = malloc ((pbm->width+7)/8);
  334. + overflow_add(pbm->width, 7);
  335. + pbm->revdata = malloc((pbm->width+7)/8);
  336. memcpy (pbm->revdata, data, (pbm->width+7)/8);
  337. pbm->current_line--;
  338. }
  339. diff -up netpbm-10.58.01/converter/pbm/pbmtoppa/pbmtoppa.c.security-code netpbm-10.58.01/converter/pbm/pbmtoppa/pbmtoppa.c
  340. --- netpbm-10.58.01/converter/pbm/pbmtoppa/pbmtoppa.c.security-code 2012-04-09 15:31:45.000000000 +0200
  341. +++ netpbm-10.58.01/converter/pbm/pbmtoppa/pbmtoppa.c 2012-04-09 15:40:03.196619876 +0200
  342. @@ -441,6 +441,7 @@ main(int argc, char *argv[]) {
  343. pm_error("main(): unrecognized parameter '%s'", argv[argn]);
  344. }
  345. + overflow_add(Width, 7);
  346. Pwidth=(Width+7)/8;
  347. printer.fptr=out;
  348. diff -up netpbm-10.58.01/converter/pbm/pbmtoxbm.c.security-code netpbm-10.58.01/converter/pbm/pbmtoxbm.c
  349. --- netpbm-10.58.01/converter/pbm/pbmtoxbm.c.security-code 2012-04-09 15:31:45.000000000 +0200
  350. +++ netpbm-10.58.01/converter/pbm/pbmtoxbm.c 2012-04-09 15:40:03.196619876 +0200
  351. @@ -335,6 +335,8 @@ convertRaster(FILE * const ifP,
  352. unsigned char * bitrow;
  353. unsigned int row;
  354. +
  355. + overflow_add(cols, padright);
  356. putinit(xbmVersion);
  357. diff -up netpbm-10.58.01/converter/pbm/pbmtoybm.c.security-code netpbm-10.58.01/converter/pbm/pbmtoybm.c
  358. --- netpbm-10.58.01/converter/pbm/pbmtoybm.c.security-code 2012-04-09 15:31:45.000000000 +0200
  359. +++ netpbm-10.58.01/converter/pbm/pbmtoybm.c 2012-04-09 15:40:03.197619863 +0200
  360. @@ -113,6 +113,7 @@ main(int argc, const char *argv[]) {
  361. bitrow = pbm_allocrow(cols);
  362. /* Compute padding to round cols up to the nearest multiple of 16. */
  363. + overflow_add(cols, 16);
  364. padright = ((cols + 15) / 16) * 16 - cols;
  365. putinit(cols, rows);
  366. diff -up netpbm-10.58.01/converter/pbm/pbmtozinc.c.security-code netpbm-10.58.01/converter/pbm/pbmtozinc.c
  367. --- netpbm-10.58.01/converter/pbm/pbmtozinc.c.security-code 2012-04-09 15:31:45.000000000 +0200
  368. +++ netpbm-10.58.01/converter/pbm/pbmtozinc.c 2012-04-09 15:40:03.197619863 +0200
  369. @@ -65,6 +65,7 @@ main(int argc, char * argv[]) {
  370. bitrow = pbm_allocrow( cols );
  371. /* Compute padding to round cols up to the nearest multiple of 16. */
  372. + overflow_add(cols, 16);
  373. padright = ( ( cols + 15 ) / 16 ) * 16 - cols;
  374. printf( "USHORT %s[] = {\n",name);
  375. diff -up netpbm-10.58.01/converter/pbm/pbmto10x.c.security-code netpbm-10.58.01/converter/pbm/pbmto10x.c
  376. --- netpbm-10.58.01/converter/pbm/pbmto10x.c.security-code 2012-04-09 15:31:45.000000000 +0200
  377. +++ netpbm-10.58.01/converter/pbm/pbmto10x.c 2012-04-09 15:40:03.197619863 +0200
  378. @@ -162,7 +162,7 @@ main(int argc, char * argv[]) {
  379. res_60x72();
  380. pm_close(ifp);
  381. - exit(0);
  382. + return 0;
  383. }
  384. diff -up netpbm-10.58.01/converter/pbm/pbmto4425.c.security-code netpbm-10.58.01/converter/pbm/pbmto4425.c
  385. --- netpbm-10.58.01/converter/pbm/pbmto4425.c.security-code 2012-04-09 15:31:45.000000000 +0200
  386. +++ netpbm-10.58.01/converter/pbm/pbmto4425.c 2012-04-09 15:40:03.198619851 +0200
  387. @@ -2,6 +2,7 @@
  388. #include "nstring.h"
  389. #include "pbm.h"
  390. +#include <string.h>
  391. static char bit_table[2][3] = {
  392. {1, 4, 0x10},
  393. @@ -160,7 +161,7 @@ main(int argc, char * argv[]) {
  394. xres = vmap_width * 2;
  395. yres = vmap_height * 3;
  396. - vmap = malloc(vmap_width * vmap_height * sizeof(char));
  397. + vmap = malloc3(vmap_width, vmap_height, sizeof(char));
  398. if(vmap == NULL)
  399. {
  400. pm_error( "Cannot allocate memory" );
  401. diff -up netpbm-10.58.01/converter/pbm/pktopbm.c.security-code netpbm-10.58.01/converter/pbm/pktopbm.c
  402. --- netpbm-10.58.01/converter/pbm/pktopbm.c.security-code 2012-04-09 15:31:45.000000000 +0200
  403. +++ netpbm-10.58.01/converter/pbm/pktopbm.c 2012-04-09 15:40:03.198619851 +0200
  404. @@ -277,6 +277,7 @@ main(int argc, char *argv[]) {
  405. if (flagbyte == 7) { /* long form preamble */
  406. integer packetlength = get32() ; /* character packet length */
  407. car = get32() ; /* character number */
  408. + overflow_add(packetlength, pktopbm_pkloc);
  409. endofpacket = packetlength + pktopbm_pkloc;
  410. /* calculate end of packet */
  411. if ((car >= MAXPKCHAR) || !filename[car]) {
  412. diff -up netpbm-10.58.01/converter/pbm/thinkjettopbm.l.security-code netpbm-10.58.01/converter/pbm/thinkjettopbm.l
  413. --- netpbm-10.58.01/converter/pbm/thinkjettopbm.l.security-code 2012-04-09 15:31:45.000000000 +0200
  414. +++ netpbm-10.58.01/converter/pbm/thinkjettopbm.l 2012-04-09 15:40:03.199619839 +0200
  415. @@ -114,7 +114,9 @@ DIG [0-9]
  416. <RASTERMODE>\033\*b{DIG}+W {
  417. int l;
  418. if (rowCount >= rowCapacity) {
  419. + overflow_add(rowCapacity, 100);
  420. rowCapacity += 100;
  421. + overflow2(rowCapacity, sizeof *rows);
  422. rows = realloc (rows, rowCapacity * sizeof *rows);
  423. if (rows == NULL)
  424. pm_error ("Out of memory.");
  425. @@ -226,6 +228,8 @@ yywrap (void)
  426. /*
  427. * Quite simple since ThinkJet bit arrangement matches PBM
  428. */
  429. +
  430. + overflow2(maxRowLength, 8);
  431. pbm_writepbminit(stdout, maxRowLength*8, rowCount, 0);
  432. packed_bitrow = malloc(maxRowLength);
  433. diff -up netpbm-10.58.01/converter/pbm/ybmtopbm.c.security-code netpbm-10.58.01/converter/pbm/ybmtopbm.c
  434. --- netpbm-10.58.01/converter/pbm/ybmtopbm.c.security-code 2012-04-09 15:31:45.000000000 +0200
  435. +++ netpbm-10.58.01/converter/pbm/ybmtopbm.c 2012-04-09 15:40:03.199619839 +0200
  436. @@ -49,6 +49,7 @@ getinit(FILE * const ifP,
  437. pm_error("EOF / read error");
  438. *depthP = 1;
  439. + overflow_add(*colsP, 15);
  440. *padrightP = ((*colsP + 15) / 16) * 16 - *colsP;
  441. }
  442. diff -up netpbm-10.58.01/converter/pgm/lispmtopgm.c.security-code netpbm-10.58.01/converter/pgm/lispmtopgm.c
  443. --- netpbm-10.58.01/converter/pgm/lispmtopgm.c.security-code 2012-04-09 15:31:42.000000000 +0200
  444. +++ netpbm-10.58.01/converter/pgm/lispmtopgm.c 2012-04-09 15:40:03.199619839 +0200
  445. @@ -58,6 +58,7 @@ main( argc, argv )
  446. pm_error( "depth (%d bits) is too large", depth);
  447. pgm_writepgminit( stdout, cols, rows, (gray) maxval, 0 );
  448. + overflow_add(cols, 7);
  449. grayrow = pgm_allocrow( ( cols + 7 ) / 8 * 8 );
  450. for ( row = 0; row < rows; ++row )
  451. @@ -102,7 +103,9 @@ getinit( file, colsP, rowsP, depthP, pad
  452. if ( *depthP == 0 )
  453. *depthP = 1; /* very old file */
  454. -
  455. +
  456. + overflow_add((int)colsP, 31);
  457. +
  458. *padrightP = ( ( *colsP + 31 ) / 32 ) * 32 - *colsP;
  459. if ( *colsP != (cols_32 - *padrightP) ) {
  460. diff -up netpbm-10.58.01/converter/pgm/psidtopgm.c.security-code netpbm-10.58.01/converter/pgm/psidtopgm.c
  461. --- netpbm-10.58.01/converter/pgm/psidtopgm.c.security-code 2012-04-09 15:31:42.000000000 +0200
  462. +++ netpbm-10.58.01/converter/pgm/psidtopgm.c 2012-04-09 15:40:03.200619827 +0200
  463. @@ -78,6 +78,7 @@ main(int argc,
  464. pm_error("bits/sample (%d) is too large.", bitspersample);
  465. pgm_writepgminit(stdout, cols, rows, maxval, 0);
  466. + overflow_add(cols, 7);
  467. grayrow = pgm_allocrow((cols + 7) / 8 * 8);
  468. for (row = 0; row < rows; ++row) {
  469. unsigned int col;
  470. diff -up netpbm-10.58.01/converter/ppm/ilbmtoppm.c.security-code netpbm-10.58.01/converter/ppm/ilbmtoppm.c
  471. --- netpbm-10.58.01/converter/ppm/ilbmtoppm.c.security-code 2012-04-09 15:31:44.000000000 +0200
  472. +++ netpbm-10.58.01/converter/ppm/ilbmtoppm.c 2012-04-09 15:40:03.201619815 +0200
  473. @@ -592,6 +592,7 @@ decode_row(FILE * const ifP,
  474. rawtype *chp;
  475. cols = bmhdP->w;
  476. + overflow_add(cols, 15);
  477. bytes = RowBytes(cols);
  478. for( plane = 0; plane < nPlanes; plane++ ) {
  479. int mask;
  480. @@ -679,6 +680,23 @@ decode_mask(FILE * const ifP,
  481. Multipalette handling
  482. ****************************************************************************/
  483. +static void *
  484. +xmalloc2(x, y)
  485. + int x;
  486. + int y;
  487. +{
  488. + void *mem;
  489. +
  490. + overflow2(x,y);
  491. + if( x * y == 0 )
  492. + return NULL;
  493. +
  494. + mem = malloc2(x,y);
  495. + if( mem == NULL )
  496. + pm_error("out of memory allocating %d bytes", x * y);
  497. + return mem;
  498. +}
  499. +
  500. static void
  501. multi_adjust(cmap, row, palchange)
  502. @@ -1341,6 +1359,9 @@ dcol_to_ppm(FILE * const ifP,
  503. if( redmaxval != maxval || greenmaxval != maxval || bluemaxval != maxval )
  504. pm_message("scaling colors to %d bits", pm_maxvaltobits(maxval));
  505. + overflow_add(redmaxval, 1);
  506. + overflow_add(greenmaxval, 1);
  507. + overflow_add(bluemaxval, 1);
  508. MALLOCARRAY_NOFAIL(redtable, redmaxval +1);
  509. MALLOCARRAY_NOFAIL(greentable, greenmaxval +1);
  510. MALLOCARRAY_NOFAIL(bluetable, bluemaxval +1);
  511. @@ -1763,7 +1784,9 @@ PCHG_ConvertSmall(PCHG, cmap, mask, data
  512. ChangeCount32 = *data++;
  513. datasize -= 2;
  514. + overflow_add(ChangeCount16, ChangeCount32);
  515. changes = ChangeCount16 + ChangeCount32;
  516. + overflow_add(changes, 1);
  517. for( i = 0; i < changes; i++ ) {
  518. if( totalchanges >= PCHG->TotalChanges ) goto fail;
  519. if( datasize < 2 ) goto fail;
  520. @@ -2028,6 +2051,9 @@ read_pchg(FILE * const ifp,
  521. cmap->mp_change[i] = NULL;
  522. if( PCHG.StartLine < 0 ) {
  523. int nch;
  524. + if(PCHG.MaxReg < PCHG.MinReg)
  525. + pm_error("assert: MinReg > MaxReg");
  526. + overflow_add(PCHG.MaxReg-PCHG.MinReg, 2);
  527. nch = PCHG.MaxReg - PCHG.MinReg +1;
  528. MALLOCARRAY_NOFAIL(cmap->mp_init, nch + 1);
  529. for( i = 0; i < nch; i++ )
  530. @@ -2104,6 +2130,7 @@ process_body( FILE * const ifp,
  531. if( typeid == ID_ILBM ) {
  532. int isdeep;
  533. + overflow_add(bmhdP->w, 15);
  534. MALLOCARRAY_NOFAIL(ilbmrow, RowBytes(bmhdP->w));
  535. *viewportmodesP |= fakeviewport; /* -isham/-isehb */
  536. diff -up netpbm-10.58.01/converter/ppm/imgtoppm.c.security-code netpbm-10.58.01/converter/ppm/imgtoppm.c
  537. --- netpbm-10.58.01/converter/ppm/imgtoppm.c.security-code 2012-04-09 15:31:44.000000000 +0200
  538. +++ netpbm-10.58.01/converter/ppm/imgtoppm.c 2012-04-09 15:40:03.202619802 +0200
  539. @@ -84,6 +84,7 @@ main(int argc, char ** argv) {
  540. len = atoi((char*) buf );
  541. if ( fread( buf, len, 1, ifp ) != 1 )
  542. pm_error( "bad colormap buf" );
  543. + overflow2(cmaplen, 3);
  544. if ( cmaplen * 3 != len )
  545. {
  546. pm_message(
  547. @@ -105,6 +106,7 @@ main(int argc, char ** argv) {
  548. pm_error( "bad pixel data header" );
  549. buf[8] = '\0';
  550. len = atoi((char*) buf );
  551. + overflow2(cols, rows);
  552. if ( len != cols * rows )
  553. pm_message(
  554. "pixel data length (%d) does not match image size (%d)",
  555. diff -up netpbm-10.58.01/converter/ppm/Makefile.security-code netpbm-10.58.01/converter/ppm/Makefile
  556. --- netpbm-10.58.01/converter/ppm/Makefile.security-code 2012-04-09 15:31:44.000000000 +0200
  557. +++ netpbm-10.58.01/converter/ppm/Makefile 2012-04-09 15:40:03.202619802 +0200
  558. @@ -11,7 +11,7 @@ SUBDIRS = hpcdtoppm ppmtompeg
  559. PORTBINARIES = 411toppm eyuvtoppm gouldtoppm ilbmtoppm imgtoppm \
  560. leaftoppm mtvtoppm neotoppm \
  561. - pcxtoppm pc1toppm pi1toppm picttoppm pjtoppm \
  562. + pcxtoppm pc1toppm pi1toppm pjtoppm \
  563. ppmtoacad ppmtoapplevol ppmtoarbtxt ppmtoascii \
  564. ppmtobmp ppmtoeyuv ppmtogif ppmtoicr ppmtoilbm \
  565. ppmtoleaf ppmtolj ppmtomitsu ppmtoneo \
  566. diff -up netpbm-10.58.01/converter/ppm/pcxtoppm.c.security-code netpbm-10.58.01/converter/ppm/pcxtoppm.c
  567. --- netpbm-10.58.01/converter/ppm/pcxtoppm.c.security-code 2012-04-09 15:31:44.000000000 +0200
  568. +++ netpbm-10.58.01/converter/ppm/pcxtoppm.c 2012-04-09 15:40:03.203619789 +0200
  569. @@ -409,6 +409,7 @@ pcx_planes_to_pixels(pixels, bitplanes,
  570. /*
  571. * clear the pixel buffer
  572. */
  573. + overflow2(bytesperline, 8);
  574. npixels = (bytesperline * 8) / bitsperpixel;
  575. p = pixels;
  576. while (--npixels >= 0)
  577. @@ -470,6 +471,7 @@ pcx_16col_to_ppm(FILE * const ifP,
  578. }
  579. /* BytesPerLine should be >= BitsPerPixel * cols / 8 */
  580. + overflow2(BytesPerLine, 8);
  581. rawcols = BytesPerLine * 8 / BitsPerPixel;
  582. if (headerCols > rawcols) {
  583. pm_message("warning - BytesPerLine = %d, "
  584. diff -up netpbm-10.58.01/converter/ppm/picttoppm.c.security-code netpbm-10.58.01/converter/ppm/picttoppm.c
  585. --- netpbm-10.58.01/converter/ppm/picttoppm.c.security-code 2012-04-09 15:31:44.000000000 +0200
  586. +++ netpbm-10.58.01/converter/ppm/picttoppm.c 2012-04-09 15:40:03.205619763 +0200
  587. @@ -1,3 +1,5 @@
  588. +#error "Unfixable. Don't ship me"
  589. +
  590. /*
  591. * picttoppm.c -- convert a MacIntosh PICT file to PPM format.
  592. *
  593. diff -up netpbm-10.58.01/converter/ppm/pjtoppm.c.security-code netpbm-10.58.01/converter/ppm/pjtoppm.c
  594. --- netpbm-10.58.01/converter/ppm/pjtoppm.c.security-code 2012-04-09 15:31:44.000000000 +0200
  595. +++ netpbm-10.58.01/converter/ppm/pjtoppm.c 2012-04-09 15:40:03.206619751 +0200
  596. @@ -127,19 +127,21 @@ main(argc, argv)
  597. case 'V': /* send plane */
  598. case 'W': /* send last plane */
  599. if (rows == -1 || r >= rows || image == NULL) {
  600. - if (rows == -1 || r >= rows)
  601. + if (rows == -1 || r >= rows) {
  602. + overflow_add(rows, 100);
  603. rows += 100;
  604. + }
  605. if (image == NULL) {
  606. - MALLOCARRAY(image, rows * planes);
  607. - MALLOCARRAY(imlen, rows * planes);
  608. + image = (unsigned char **)
  609. + malloc3(rows , planes , sizeof(unsigned char *));
  610. + imlen = (int *) malloc3(rows , planes, sizeof(int));
  611. }
  612. else {
  613. + overflow2(rows,planes);
  614. image = (unsigned char **)
  615. - realloc(image,
  616. - rows * planes *
  617. + realloc2(image, rows * planes,
  618. sizeof(unsigned char *));
  619. - imlen = (int *)
  620. - realloc(imlen, rows * planes * sizeof(int));
  621. + imlen = (int *) realloc2(imlen, rows * planes, sizeof(int));
  622. }
  623. }
  624. if (image == NULL || imlen == NULL)
  625. @@ -212,8 +214,10 @@ main(argc, argv)
  626. for (i = 0, c = 0; c < imlen[p + r * planes]; c += 2)
  627. for (cmd = image[p + r * planes][c],
  628. val = image[p + r * planes][c+1];
  629. - cmd >= 0 && i < newcols; cmd--, i++)
  630. + cmd >= 0 && i < newcols; cmd--, i++) {
  631. buf[i] = val;
  632. + overflow_add(i, 1);
  633. + }
  634. cols = cols > i ? cols : i;
  635. free(image[p + r * planes]);
  636. /*
  637. @@ -224,6 +228,7 @@ main(argc, argv)
  638. image[p + r * planes] = (unsigned char *) realloc(buf, i);
  639. }
  640. }
  641. + overflow2(cols, 8);
  642. cols *= 8;
  643. }
  644. diff -up netpbm-10.58.01/converter/ppm/ppmtoeyuv.c.security-code netpbm-10.58.01/converter/ppm/ppmtoeyuv.c
  645. --- netpbm-10.58.01/converter/ppm/ppmtoeyuv.c.security-code 2012-04-09 15:31:42.000000000 +0200
  646. +++ netpbm-10.58.01/converter/ppm/ppmtoeyuv.c 2012-04-09 15:40:03.206619751 +0200
  647. @@ -114,6 +114,7 @@ create_multiplication_tables(const pixva
  648. int index;
  649. + overflow_add(maxval, 1);
  650. MALLOCARRAY_NOFAIL(mult299 , maxval+1);
  651. MALLOCARRAY_NOFAIL(mult587 , maxval+1);
  652. MALLOCARRAY_NOFAIL(mult114 , maxval+1);
  653. diff -up netpbm-10.58.01/converter/ppm/ppmtoicr.c.security-code netpbm-10.58.01/converter/ppm/ppmtoicr.c
  654. --- netpbm-10.58.01/converter/ppm/ppmtoicr.c.security-code 2012-04-09 15:31:44.000000000 +0200
  655. +++ netpbm-10.58.01/converter/ppm/ppmtoicr.c 2012-04-09 15:40:03.207619739 +0200
  656. @@ -169,7 +169,7 @@ char* argv[];
  657. if (rleflag) {
  658. pm_message("sending run-length encoded picture data ..." );
  659. - testimage = (char*) malloc(rows*cols);
  660. + testimage = (char*) malloc2(rows, cols);
  661. p = testimage;
  662. for (i=0; i<rows; i++)
  663. for (j=0; j<cols; j++)
  664. diff -up netpbm-10.58.01/converter/ppm/ppmtoilbm.c.security-code netpbm-10.58.01/converter/ppm/ppmtoilbm.c
  665. --- netpbm-10.58.01/converter/ppm/ppmtoilbm.c.security-code 2012-04-09 15:31:42.000000000 +0200
  666. +++ netpbm-10.58.01/converter/ppm/ppmtoilbm.c 2012-04-09 15:40:03.208619727 +0200
  667. @@ -1220,6 +1220,7 @@ ppm_to_rgb8(ifP, cols, rows, maxval)
  668. maskmethod = 0; /* no masking - RGB8 uses genlock bits */
  669. compmethod = 4; /* RGB8 files are always compressed */
  670. + overflow2(cols, 4);
  671. MALLOCARRAY_NOFAIL(compr_row, cols * 4);
  672. if( maxval != 255 ) {
  673. @@ -1308,6 +1309,7 @@ ppm_to_rgbn(ifP, cols, rows, maxval)
  674. maskmethod = 0; /* no masking - RGBN uses genlock bits */
  675. compmethod = 4; /* RGBN files are always compressed */
  676. + overflow2(cols, 2);
  677. MALLOCARRAY_NOFAIL(compr_row, cols * 2);
  678. if( maxval != 15 ) {
  679. @@ -1785,6 +1787,7 @@ make_val_table(oldmaxval, newmaxval)
  680. unsigned int i;
  681. int * table;
  682. + overflow_add(oldmaxval, 1);
  683. MALLOCARRAY_NOFAIL(table, oldmaxval + 1);
  684. for (i = 0; i <= oldmaxval; ++i)
  685. table[i] = ROUNDDIV(i * newmaxval, oldmaxval);
  686. @@ -2293,8 +2296,11 @@ main(int argc, char ** argv) {
  687. MALLOCARRAY_NOFAIL(coded_rowbuf, RowBytes(cols));
  688. for (i = 0; i < RowBytes(cols); ++i)
  689. coded_rowbuf[i] = 0;
  690. - if (DO_COMPRESS)
  691. + if (DO_COMPRESS) {
  692. + overflow2(cols,2);
  693. + overflow_add(cols*2,2);
  694. MALLOCARRAY_NOFAIL(compr_rowbuf, WORSTCOMPR(RowBytes(cols)));
  695. + }
  696. }
  697. switch (mode) {
  698. diff -up netpbm-10.58.01/converter/ppm/ppmtolj.c.security-code netpbm-10.58.01/converter/ppm/ppmtolj.c
  699. --- netpbm-10.58.01/converter/ppm/ppmtolj.c.security-code 2012-04-09 15:31:42.000000000 +0200
  700. +++ netpbm-10.58.01/converter/ppm/ppmtolj.c 2012-04-09 15:40:03.210619701 +0200
  701. @@ -181,7 +181,8 @@ int main(int argc, char *argv[]) {
  702. ppm_readppminit( ifp, &cols, &rows, &maxval, &format );
  703. pixelrow = ppm_allocrow( cols );
  704. -
  705. +
  706. + overflow2(cols, 6);
  707. obuf = (unsigned char *) pm_allocrow(cols * 3, sizeof(unsigned char));
  708. cbuf = (unsigned char *) pm_allocrow(cols * 6, sizeof(unsigned char));
  709. if (mode == C_TRANS_MODE_DELTA)
  710. diff -up netpbm-10.58.01/converter/ppm/ppmtomitsu.c.security-code netpbm-10.58.01/converter/ppm/ppmtomitsu.c
  711. --- netpbm-10.58.01/converter/ppm/ppmtomitsu.c.security-code 2012-04-09 15:31:44.000000000 +0200
  712. +++ netpbm-10.58.01/converter/ppm/ppmtomitsu.c 2012-04-09 15:40:03.210619702 +0200
  713. @@ -685,6 +685,8 @@ main(int argc, char * argv[]) {
  714. medias = MSize_User;
  715. if (dpi300) {
  716. + overflow2(medias.maxcols, 2);
  717. + overflow2(medias.maxrows, 2);
  718. medias.maxcols *= 2;
  719. medias.maxrows *= 2;
  720. }
  721. diff -up netpbm-10.58.01/converter/ppm/ppmtopcx.c.security-code netpbm-10.58.01/converter/ppm/ppmtopcx.c
  722. --- netpbm-10.58.01/converter/ppm/ppmtopcx.c.security-code 2012-04-09 15:31:44.000000000 +0200
  723. +++ netpbm-10.58.01/converter/ppm/ppmtopcx.c 2012-04-09 15:40:03.210619702 +0200
  724. @@ -419,6 +419,8 @@ ppmTo16ColorPcx(pixel ** cons
  725. else Planes = 1;
  726. }
  727. }
  728. + overflow2(BitsPerPixel, cols);
  729. + overflow_add(BitsPerPixel * cols, 7);
  730. BytesPerLine = ((cols * BitsPerPixel) + 7) / 8;
  731. MALLOCARRAY_NOFAIL(indexRow, cols);
  732. MALLOCARRAY_NOFAIL(planesrow, BytesPerLine);
  733. diff -up netpbm-10.58.01/converter/ppm/ppmtopict.c.security-code netpbm-10.58.01/converter/ppm/ppmtopict.c
  734. --- netpbm-10.58.01/converter/ppm/ppmtopict.c.security-code 2012-04-09 15:31:42.000000000 +0200
  735. +++ netpbm-10.58.01/converter/ppm/ppmtopict.c 2012-04-09 15:40:03.211619690 +0200
  736. @@ -441,6 +441,8 @@ main(int argc, const char ** argv) {
  737. putShort(stdout, 0); /* mode */
  738. /* Finally, write out the data. */
  739. + overflow_add(cols/MAX_COUNT, 1);
  740. + overflow_add(cols, cols/MAX_COUNT+1);
  741. packed = malloc((unsigned)(cols+cols/MAX_COUNT+1));
  742. for (row = 0, oc = 0; row < rows; row++)
  743. oc += putRow(stdout, row, cols, pixels[row], packed);
  744. diff -up netpbm-10.58.01/converter/ppm/ppmtopj.c.security-code netpbm-10.58.01/converter/ppm/ppmtopj.c
  745. --- netpbm-10.58.01/converter/ppm/ppmtopj.c.security-code 2012-04-09 15:31:44.000000000 +0200
  746. +++ netpbm-10.58.01/converter/ppm/ppmtopj.c 2012-04-09 15:40:03.212619677 +0200
  747. @@ -179,6 +179,7 @@ char *argv[];
  748. pixels = ppm_readppm( ifp, &cols, &rows, &maxval );
  749. pm_close( ifp );
  750. + overflow2(cols,2);
  751. obuf = (unsigned char *) pm_allocrow(cols, sizeof(unsigned char));
  752. cbuf = (unsigned char *) pm_allocrow(cols * 2, sizeof(unsigned char));
  753. diff -up netpbm-10.58.01/converter/ppm/ppmtopjxl.c.security-code netpbm-10.58.01/converter/ppm/ppmtopjxl.c
  754. --- netpbm-10.58.01/converter/ppm/ppmtopjxl.c.security-code 2012-04-09 15:31:44.000000000 +0200
  755. +++ netpbm-10.58.01/converter/ppm/ppmtopjxl.c 2012-04-09 15:40:03.212619677 +0200
  756. @@ -276,6 +276,8 @@ main(int argc, const char * argv[]) {
  757. pm_error("image too large; reduce with ppmscale");
  758. if (maxval > PCL_MAXVAL)
  759. pm_error("color range too large; reduce with ppmcscale");
  760. + if (cols < 0 || rows < 0)
  761. + pm_error("negative size is not possible");
  762. /* Figure out the colormap. */
  763. pm_message("Computing colormap...");
  764. @@ -296,6 +298,8 @@ main(int argc, const char * argv[]) {
  765. case 0: /* direct mode (no palette) */
  766. bpp = bitsperpixel(maxval); /* bits per pixel */
  767. bpg = bpp; bpb = bpp;
  768. + overflow2(bpp, 3);
  769. + overflow_add(bpp*3, 7);
  770. bpp = (bpp*3+7)>>3; /* bytes per pixel now */
  771. bpr = (bpp<<3)-bpg-bpb;
  772. bpp *= cols; /* bytes per row now */
  773. @@ -305,9 +309,13 @@ main(int argc, const char * argv[]) {
  774. case 3: case 7: pclindex++;
  775. default:
  776. bpp = 8/pclindex;
  777. + overflow_add(cols, bpp);
  778. + if(bpp == 0)
  779. + pm_error("assert: no bpp");
  780. bpp = (cols+bpp-1)/bpp; /* bytes per row */
  781. }
  782. }
  783. + overflow2(bpp,2);
  784. inrow = (char *)malloc((unsigned)bpp);
  785. outrow = (char *)malloc((unsigned)bpp*2);
  786. runcnt = (signed char *)malloc((unsigned)bpp);
  787. diff -up netpbm-10.58.01/converter/ppm/ppmtowinicon.c.security-code netpbm-10.58.01/converter/ppm/ppmtowinicon.c
  788. --- netpbm-10.58.01/converter/ppm/ppmtowinicon.c.security-code 2012-04-09 15:31:44.000000000 +0200
  789. +++ netpbm-10.58.01/converter/ppm/ppmtowinicon.c 2012-04-09 15:40:03.213619664 +0200
  790. @@ -12,6 +12,7 @@
  791. #include <math.h>
  792. #include <string.h>
  793. +#include <stdlib.h>
  794. #include "pm_c_util.h"
  795. #include "winico.h"
  796. @@ -219,6 +220,7 @@ createAndBitmap (gray ** const ba, int c
  797. MALLOCARRAY_NOFAIL(rowData, rows);
  798. icBitmap->xBytes = xBytes;
  799. icBitmap->data = rowData;
  800. + overflow2(xBytes, rows);
  801. icBitmap->size = xBytes * rows;
  802. for (y=0;y<rows;y++) {
  803. u1 * row;
  804. @@ -347,6 +349,7 @@ create4Bitmap (pixel ** const pa, int co
  805. MALLOCARRAY_NOFAIL(rowData, rows);
  806. icBitmap->xBytes = xBytes;
  807. icBitmap->data = rowData;
  808. + overflow2(xBytes, rows);
  809. icBitmap->size = xBytes * rows;
  810. for (y=0;y<rows;y++) {
  811. @@ -407,6 +410,7 @@ create8Bitmap (pixel ** const pa, int co
  812. MALLOCARRAY_NOFAIL(rowData, rows);
  813. icBitmap->xBytes = xBytes;
  814. icBitmap->data = rowData;
  815. + overflow2(xBytes, rows);
  816. icBitmap->size = xBytes * rows;
  817. for (y=0;y<rows;y++) {
  818. @@ -714,6 +718,10 @@ addEntryToIcon(MS_Ico const MSIcon
  819. entry->bitcount = bpp;
  820. entry->ih = createInfoHeader(entry, xorBitmap, andBitmap);
  821. entry->colors = palette->colors;
  822. + overflow2(4, entry->color_count);
  823. + overflow_add(xorBitmap->size, andBitmap->size);
  824. + overflow_add(xorBitmap->size + andBitmap->size, 40);
  825. + overflow_add(xorBitmap->size + andBitmap->size + 40, 4 * entry->color_count);
  826. entry->size_in_bytes =
  827. xorBitmap->size + andBitmap->size + 40 + (4 * entry->color_count);
  828. if (verbose)
  829. diff -up netpbm-10.58.01/converter/ppm/ppmtoxpm.c.security-code netpbm-10.58.01/converter/ppm/ppmtoxpm.c
  830. --- netpbm-10.58.01/converter/ppm/ppmtoxpm.c.security-code 2012-04-09 15:31:44.000000000 +0200
  831. +++ netpbm-10.58.01/converter/ppm/ppmtoxpm.c 2012-04-09 15:40:03.214619651 +0200
  832. @@ -197,6 +197,7 @@ genNumstr(unsigned int const input, int
  833. unsigned int i;
  834. /* Allocate memory for printed number. Abort if error. */
  835. + overflow_add(digits, 1);
  836. if (!(str = (char *) malloc(digits + 1)))
  837. pm_error("out of memory");
  838. @@ -314,6 +315,7 @@ genCmap(colorhist_vector const chv,
  839. unsigned int charsPerPixel;
  840. unsigned int xpmMaxval;
  841. + if (includeTransparent) overflow_add(ncolors, 1);
  842. MALLOCARRAY(cmap, cmapSize);
  843. if (cmapP == NULL)
  844. pm_error("Out of memory allocating %u bytes for a color map.",
  845. diff -up netpbm-10.58.01/converter/ppm/qrttoppm.c.security-code netpbm-10.58.01/converter/ppm/qrttoppm.c
  846. --- netpbm-10.58.01/converter/ppm/qrttoppm.c.security-code 2012-04-09 15:31:42.000000000 +0200
  847. +++ netpbm-10.58.01/converter/ppm/qrttoppm.c 2012-04-09 15:40:03.215619638 +0200
  848. @@ -46,7 +46,7 @@ main( argc, argv )
  849. ppm_writeppminit( stdout, cols, rows, maxval, 0 );
  850. pixelrow = ppm_allocrow( cols );
  851. - buf = (unsigned char *) malloc( 3 * cols );
  852. + buf = (unsigned char *) malloc2( 3 , cols );
  853. if ( buf == (unsigned char *) 0 )
  854. pm_error( "out of memory" );
  855. diff -up netpbm-10.58.01/converter/ppm/sldtoppm.c.security-code netpbm-10.58.01/converter/ppm/sldtoppm.c
  856. --- netpbm-10.58.01/converter/ppm/sldtoppm.c.security-code 2012-04-09 15:31:44.000000000 +0200
  857. +++ netpbm-10.58.01/converter/ppm/sldtoppm.c 2012-04-09 15:40:03.216619626 +0200
  858. @@ -455,6 +455,8 @@ slider(slvecfn slvec,
  859. /* Allocate image buffer and clear it to black. */
  860. + overflow_add(ixdots,1);
  861. + overflow_add(iydots,1);
  862. pixels = ppm_allocarray(pixcols = ixdots + 1, pixrows = iydots + 1);
  863. PPM_ASSIGN(rgbcolor, 0, 0, 0);
  864. ppmd_filledrectangle(pixels, pixcols, pixrows, pixmaxval, 0, 0,
  865. diff -up netpbm-10.58.01/converter/ppm/ximtoppm.c.security-code netpbm-10.58.01/converter/ppm/ximtoppm.c
  866. --- netpbm-10.58.01/converter/ppm/ximtoppm.c.security-code 2012-04-09 15:31:44.000000000 +0200
  867. +++ netpbm-10.58.01/converter/ppm/ximtoppm.c 2012-04-09 15:40:03.216619626 +0200
  868. @@ -117,6 +117,7 @@ ReadXimHeader(FILE * const in_fp,
  869. header->bits_channel = atoi(a_head.bits_per_channel);
  870. header->alpha_flag = atoi(a_head.alpha_channel);
  871. if (strlen(a_head.author)) {
  872. + overflow_add(strlen(a_head.author),1);
  873. if (!(header->author = calloc((unsigned int)strlen(a_head.author)+1,
  874. 1))) {
  875. pm_message("ReadXimHeader: can't calloc author string" );
  876. @@ -126,6 +127,7 @@ ReadXimHeader(FILE * const in_fp,
  877. strncpy(header->author, a_head.author, strlen(a_head.author));
  878. }
  879. if (strlen(a_head.date)) {
  880. + overflow_add(strlen(a_head.date),1);
  881. if (!(header->date =calloc((unsigned int)strlen(a_head.date)+1,1))){
  882. pm_message("ReadXimHeader: can't calloc date string" );
  883. return(0);
  884. @@ -134,6 +136,7 @@ ReadXimHeader(FILE * const in_fp,
  885. strncpy(header->date, a_head.date, strlen(a_head.date));
  886. }
  887. if (strlen(a_head.program)) {
  888. + overflow_add(strlen(a_head.program),1);
  889. if (!(header->program = calloc(
  890. (unsigned int)strlen(a_head.program) + 1, 1))) {
  891. pm_message("ReadXimHeader: can't calloc program string" );
  892. @@ -160,6 +163,7 @@ ReadXimHeader(FILE * const in_fp,
  893. if (header->nchannels == 3 && header->bits_channel == 8)
  894. header->ncolors = 0;
  895. else if (header->nchannels == 1 && header->bits_channel == 8) {
  896. + overflow2(header->ncolors, sizeof(Color));
  897. header->colors = (Color *)calloc((unsigned int)header->ncolors,
  898. sizeof(Color));
  899. if (header->colors == NULL) {
  900. diff -up netpbm-10.58.01/converter/ppm/yuvtoppm.c.security-code netpbm-10.58.01/converter/ppm/yuvtoppm.c
  901. --- netpbm-10.58.01/converter/ppm/yuvtoppm.c.security-code 2012-04-09 15:31:44.000000000 +0200
  902. +++ netpbm-10.58.01/converter/ppm/yuvtoppm.c 2012-04-09 15:40:03.218619602 +0200
  903. @@ -72,6 +72,7 @@ main(argc, argv)
  904. ppm_writeppminit(stdout, cols, rows, (pixval) 255, 0);
  905. pixrow = ppm_allocrow(cols);
  906. + overflow_add(cols, 1);
  907. MALLOCARRAY(yuvbuf, (cols+1)/2);
  908. if (yuvbuf == NULL)
  909. pm_error("Unable to allocate YUV buffer for %d columns.", cols);
  910. diff -up netpbm-10.58.01/editor/pamcut.c.security-code netpbm-10.58.01/editor/pamcut.c
  911. --- netpbm-10.58.01/editor/pamcut.c.security-code 2012-04-09 15:31:33.000000000 +0200
  912. +++ netpbm-10.58.01/editor/pamcut.c 2012-04-09 15:40:03.218619602 +0200
  913. @@ -655,6 +655,8 @@ cutOneImage(FILE * const ifP
  914. outpam = inpam; /* Initial value -- most fields should be same */
  915. outpam.file = ofP;
  916. + overflow_add(rightcol, 1);
  917. + overflow_add(bottomrow, 1);
  918. outpam.width = rightcol - leftcol + 1;
  919. outpam.height = bottomrow - toprow + 1;
  920. diff -up netpbm-10.58.01/editor/pbmreduce.c.security-code netpbm-10.58.01/editor/pbmreduce.c
  921. --- netpbm-10.58.01/editor/pbmreduce.c.security-code 2012-04-09 15:31:33.000000000 +0200
  922. +++ netpbm-10.58.01/editor/pbmreduce.c 2012-04-09 15:40:03.219619590 +0200
  923. @@ -94,6 +94,7 @@ main( argc, argv )
  924. if (halftone == QT_FS) {
  925. unsigned int col;
  926. /* Initialize Floyd-Steinberg. */
  927. + overflow_add(newcols, 2);
  928. MALLOCARRAY(thiserr, newcols + 2);
  929. MALLOCARRAY(nexterr, newcols + 2);
  930. if (thiserr == NULL || nexterr == NULL)
  931. diff -up netpbm-10.58.01/editor/pnmgamma.c.security-code netpbm-10.58.01/editor/pnmgamma.c
  932. --- netpbm-10.58.01/editor/pnmgamma.c.security-code 2012-04-09 15:31:34.000000000 +0200
  933. +++ netpbm-10.58.01/editor/pnmgamma.c 2012-04-09 15:40:03.220619577 +0200
  934. @@ -586,6 +586,7 @@ createGammaTables(enum transferFunction
  935. xelval ** const btableP) {
  936. /* Allocate space for the tables. */
  937. + overflow_add(maxval, 1);
  938. MALLOCARRAY(*rtableP, maxval+1);
  939. MALLOCARRAY(*gtableP, maxval+1);
  940. MALLOCARRAY(*btableP, maxval+1);
  941. diff -up netpbm-10.58.01/editor/pnmhisteq.c.security-code netpbm-10.58.01/editor/pnmhisteq.c
  942. --- netpbm-10.58.01/editor/pnmhisteq.c.security-code 2012-04-09 15:31:33.000000000 +0200
  943. +++ netpbm-10.58.01/editor/pnmhisteq.c 2012-04-09 15:40:03.220619577 +0200
  944. @@ -103,6 +103,7 @@ computeLuminosityHistogram(xel * const *
  945. unsigned int pixelCount;
  946. unsigned int * lumahist;
  947. + overflow_add(maxval, 1);
  948. MALLOCARRAY(lumahist, maxval + 1);
  949. if (lumahist == NULL)
  950. pm_error("Out of storage allocating array for %u histogram elements",
  951. diff -up netpbm-10.58.01/editor/pnmindex.csh.security-code netpbm-10.58.01/editor/pnmindex.csh
  952. --- netpbm-10.58.01/editor/pnmindex.csh.security-code 2012-04-09 15:31:33.000000000 +0200
  953. +++ netpbm-10.58.01/editor/pnmindex.csh 2012-04-09 15:40:03.221619564 +0200
  954. @@ -1,5 +1,8 @@
  955. #!/bin/csh -f
  956. #
  957. +echo "Unsafe code, needs debugging, do not ship"
  958. +exit 1
  959. +#
  960. # pnmindex - build a visual index of a bunch of anymaps
  961. #
  962. # Copyright (C) 1991 by Jef Poskanzer.
  963. diff -up netpbm-10.58.01/editor/pnmpad.c.security-code netpbm-10.58.01/editor/pnmpad.c
  964. --- netpbm-10.58.01/editor/pnmpad.c.security-code 2012-04-09 15:31:34.000000000 +0200
  965. +++ netpbm-10.58.01/editor/pnmpad.c 2012-04-09 15:40:03.221619564 +0200
  966. @@ -527,6 +527,8 @@ main(int argc, const char ** argv) {
  967. computePadSizes(cmdline, cols, rows, &lpad, &rpad, &tpad, &bpad);
  968. + overflow_add(cols, lpad);
  969. + overflow_add(cols + lpad, rpad);
  970. newcols = cols + lpad + rpad;
  971. if (PNM_FORMAT_TYPE(format) == PBM_TYPE)
  972. diff -up netpbm-10.58.01/editor/pnmremap.c.security-code netpbm-10.58.01/editor/pnmremap.c
  973. --- netpbm-10.58.01/editor/pnmremap.c.security-code 2012-04-09 15:31:33.000000000 +0200
  974. +++ netpbm-10.58.01/editor/pnmremap.c 2012-04-09 15:40:03.222619551 +0200
  975. @@ -409,7 +409,7 @@ initFserr(struct pam * const pamP,
  976. unsigned int plane;
  977. unsigned int const fserrSize = pamP->width + 2;
  978. -
  979. + overflow_add(pamP->width, 2);
  980. fserrP->width = pamP->width;
  981. MALLOCARRAY(fserrP->thiserr, pamP->depth);
  982. @@ -445,6 +445,7 @@ floydInitRow(struct pam * const pamP, st
  983. int col;
  984. + overflow_add(pamP->width, 2);
  985. for (col = 0; col < pamP->width + 2; ++col) {
  986. unsigned int plane;
  987. for (plane = 0; plane < pamP->depth; ++plane)
  988. diff -up netpbm-10.58.01/editor/pnmscalefixed.c.security-code netpbm-10.58.01/editor/pnmscalefixed.c
  989. --- netpbm-10.58.01/editor/pnmscalefixed.c.security-code 2012-04-09 15:31:34.000000000 +0200
  990. +++ netpbm-10.58.01/editor/pnmscalefixed.c 2012-04-09 15:40:03.223619538 +0200
  991. @@ -214,6 +214,8 @@ compute_output_dimensions(const struct c
  992. const int rows, const int cols,
  993. int * newrowsP, int * newcolsP) {
  994. + overflow2(rows, cols);
  995. +
  996. if (cmdline.pixels) {
  997. if (rows * cols <= cmdline.pixels) {
  998. *newrowsP = rows;
  999. @@ -265,6 +267,8 @@ compute_output_dimensions(const struct c
  1000. if (*newcolsP < 1) *newcolsP = 1;
  1001. if (*newrowsP < 1) *newrowsP = 1;
  1002. +
  1003. + overflow2(*newcolsP, *newrowsP);
  1004. }
  1005. @@ -446,6 +450,9 @@ main(int argc, char **argv ) {
  1006. unfilled. We can address that by stretching, whereas the other
  1007. case would require throwing away some of the input.
  1008. */
  1009. +
  1010. + overflow2(newcols, SCALE);
  1011. + overflow2(newrows, SCALE);
  1012. sxscale = SCALE * newcols / cols;
  1013. syscale = SCALE * newrows / rows;
  1014. diff -up netpbm-10.58.01/editor/pnmshear.c.security-code netpbm-10.58.01/editor/pnmshear.c
  1015. --- netpbm-10.58.01/editor/pnmshear.c.security-code 2012-04-09 15:31:33.000000000 +0200
  1016. +++ netpbm-10.58.01/editor/pnmshear.c 2012-04-09 15:40:03.224619526 +0200
  1017. @@ -15,6 +15,7 @@
  1018. #include <assert.h>
  1019. #include <math.h>
  1020. #include <string.h>
  1021. +#include <limits.h>
  1022. #include "pm_c_util.h"
  1023. #include "ppm.h"
  1024. @@ -236,6 +237,11 @@ main(int argc, char * argv[]) {
  1025. shearfac = fabs(tan(cmdline.angle));
  1026. + if(rows * shearfac >= INT_MAX-1)
  1027. + pm_error("image too large");
  1028. +
  1029. + overflow_add(rows * shearfac, cols+1);
  1030. +
  1031. newcols = rows * shearfac + cols + 0.999999;
  1032. pnm_writepnminit(stdout, newcols, rows, newmaxval, newformat, 0);
  1033. diff -up netpbm-10.58.01/editor/ppmdither.c.security-code netpbm-10.58.01/editor/ppmdither.c
  1034. --- netpbm-10.58.01/editor/ppmdither.c.security-code 2012-04-09 15:31:33.000000000 +0200
  1035. +++ netpbm-10.58.01/editor/ppmdither.c 2012-04-09 15:40:03.224619526 +0200
  1036. @@ -355,7 +355,11 @@ dithMatrix(unsigned int const dithPower)
  1037. unsigned int const dithMatSize =
  1038. (dithDim * sizeof(*dithMat)) + /* pointers */
  1039. (dithDim * dithDim * sizeof(**dithMat)); /* data */
  1040. -
  1041. +
  1042. + overflow2(dithDim, sizeof(*dithMat));
  1043. + overflow3(dithDim, dithDim, sizeof(**dithMat));
  1044. + overflow_add(dithDim * sizeof(*dithMat), dithDim * dithDim * sizeof(**dithMat));
  1045. +
  1046. dithMat = malloc(dithMatSize);
  1047. if (dithMat == NULL)
  1048. diff -up netpbm-10.58.01/editor/specialty/pamoil.c.security-code netpbm-10.58.01/editor/specialty/pamoil.c
  1049. --- netpbm-10.58.01/editor/specialty/pamoil.c.security-code 2012-04-09 15:31:33.000000000 +0200
  1050. +++ netpbm-10.58.01/editor/specialty/pamoil.c 2012-04-09 15:40:03.224619526 +0200
  1051. @@ -112,6 +112,7 @@ main(int argc, char *argv[] ) {
  1052. tuples = pnm_readpam(ifp, &inpam, PAM_STRUCT_SIZE(tuple_type));
  1053. pm_close(ifp);
  1054. + overflow_add(inpam.maxval, 1);
  1055. MALLOCARRAY(hist, inpam.maxval + 1);
  1056. if (hist == NULL)
  1057. pm_error("Unable to allocate memory for histogram.");
  1058. diff -up netpbm-10.58.01/generator/pbmtext.c.security-code netpbm-10.58.01/generator/pbmtext.c
  1059. --- netpbm-10.58.01/generator/pbmtext.c.security-code 2012-04-09 15:31:34.000000000 +0200
  1060. +++ netpbm-10.58.01/generator/pbmtext.c 2012-04-09 15:40:03.225619514 +0200
  1061. @@ -96,12 +96,14 @@ parseCommandLine(int argc, const char **
  1062. for (i = 1; i < argc; ++i) {
  1063. if (i > 1) {
  1064. + overflow_add(totaltextsize, 1);
  1065. totaltextsize += 1;
  1066. text = realloc(text, totaltextsize);
  1067. if (text == NULL)
  1068. pm_error("out of memory allocating space for input text");
  1069. strcat(text, " ");
  1070. }
  1071. + overflow_add(totaltextsize, strlen(argv[i]));
  1072. totaltextsize += strlen(argv[i]);
  1073. text = realloc(text, totaltextsize);
  1074. if (text == NULL)
  1075. @@ -712,6 +714,7 @@ getText(const char cmdline_text
  1076. pm_error("A line of input text is longer than %u characters."
  1077. "Cannot process.", (unsigned)sizeof(buf)-1);
  1078. if (lineCount >= maxlines) {
  1079. + overflow2(maxlines, 2);
  1080. maxlines *= 2;
  1081. REALLOCARRAY(text_array, maxlines);
  1082. if (text_array == NULL)
  1083. @@ -832,6 +835,7 @@ main(int argc, const char *argv[]) {
  1084. hmargin = fontP->maxwidth;
  1085. } else {
  1086. vmargin = fontP->maxheight;
  1087. + overflow2(2, fontP->maxwidth);
  1088. hmargin = 2 * fontP->maxwidth;
  1089. }
  1090. }
  1091. diff -up netpbm-10.58.01/generator/pgmcrater.c.security-code netpbm-10.58.01/generator/pgmcrater.c
  1092. --- netpbm-10.58.01/generator/pgmcrater.c.security-code 2012-04-09 15:31:34.000000000 +0200
  1093. +++ netpbm-10.58.01/generator/pgmcrater.c 2012-04-09 15:40:03.226619502 +0200
  1094. @@ -130,7 +130,7 @@ static void gencraters()
  1095. /* Acquire the elevation array and initialize it to mean
  1096. surface elevation. */
  1097. - MALLOCARRAY(aux, SCRX * SCRY);
  1098. + aux = (unsigned short *) malloc3(SCRX, SCRY, sizeof(short));
  1099. if (aux == NULL)
  1100. pm_error("out of memory allocating elevation array");
  1101. diff -up netpbm-10.58.01/generator/pgmkernel.c.security-code netpbm-10.58.01/generator/pgmkernel.c
  1102. --- netpbm-10.58.01/generator/pgmkernel.c.security-code 2012-04-09 15:31:34.000000000 +0200
  1103. +++ netpbm-10.58.01/generator/pgmkernel.c 2012-04-09 15:40:03.226619502 +0200
  1104. @@ -68,7 +68,7 @@ main ( argc, argv )
  1105. kycenter = (fysize - 1) / 2.0;
  1106. ixsize = fxsize + 0.999;
  1107. iysize = fysize + 0.999;
  1108. - MALLOCARRAY(fkernel, ixsize * iysize);
  1109. + fkernel = (double *) malloc3 (ixsize, iysize, sizeof(double));
  1110. for (i = 0; i < iysize; i++)
  1111. for (j = 0; j < ixsize; j++) {
  1112. fkernel[i*ixsize+j] = 1.0 / (1.0 + w * sqrt((double)
  1113. diff -up netpbm-10.58.01/lib/libpam.c.security-code netpbm-10.58.01/lib/libpam.c
  1114. --- netpbm-10.58.01/lib/libpam.c.security-code 2012-04-09 15:31:38.000000000 +0200
  1115. +++ netpbm-10.58.01/lib/libpam.c 2012-04-09 15:40:03.227619490 +0200
  1116. @@ -220,7 +220,8 @@ allocPamRow(const struct pam * const pam
  1117. unsigned int const bytesPerTuple = allocationDepth(pamP) * sizeof(sample);
  1118. tuple * tuplerow;
  1119. - tuplerow = malloc(pamP->width * (sizeof(tuple *) + bytesPerTuple));
  1120. + overflow_add(sizeof(tuple *), bytesPerTuple);
  1121. + tuplerow = malloc2(pamP->width, (sizeof(tuple *) + bytesPerTuple));
  1122. if (tuplerow != NULL) {
  1123. /* Now we initialize the pointers to the individual tuples
  1124. diff -up netpbm-10.58.01/lib/libpammap.c.security-code netpbm-10.58.01/lib/libpammap.c
  1125. --- netpbm-10.58.01/lib/libpammap.c.security-code 2012-04-09 15:31:38.000000000 +0200
  1126. +++ netpbm-10.58.01/lib/libpammap.c 2012-04-09 15:40:03.228619477 +0200
  1127. @@ -104,6 +104,8 @@ allocTupleIntListItem(struct pam * const
  1128. */
  1129. struct tupleint_list_item * retval;
  1130. + overflow2(pamP->depth, sizeof(sample));
  1131. + overflow_add(sizeof(*retval)-sizeof(retval->tupleint.tuple), pamP->depth*sizeof(sample));
  1132. unsigned int const size =
  1133. sizeof(*retval) - sizeof(retval->tupleint.tuple)
  1134. + pamP->depth * sizeof(sample);
  1135. diff -up netpbm-10.58.01/lib/libpbm1.c.security-code netpbm-10.58.01/lib/libpbm1.c
  1136. --- netpbm-10.58.01/lib/libpbm1.c.security-code 2012-04-09 15:31:38.000000000 +0200
  1137. +++ netpbm-10.58.01/lib/libpbm1.c 2012-04-09 15:40:03.228619477 +0200
  1138. @@ -77,6 +77,7 @@ pbm_check(FILE * file, const enum pm_che
  1139. pm_message("pm_filepos passed to pm_check() is %u bytes",
  1140. sizeof(pm_filepos));
  1141. #endif
  1142. + overflow2(bytes_per_row, rows);
  1143. pm_check(file, check_type, need_raster_size, retval_p);
  1144. }
  1145. }
  1146. diff -up netpbm-10.58.01/lib/libpm.c.security-code netpbm-10.58.01/lib/libpm.c
  1147. --- netpbm-10.58.01/lib/libpm.c.security-code 2012-04-09 15:31:38.000000000 +0200
  1148. +++ netpbm-10.58.01/lib/libpm.c 2012-04-09 15:40:03.229619464 +0200
  1149. @@ -808,4 +808,53 @@ pm_parse_height(const char * const arg)
  1150. }
  1151. +/*
  1152. + * Maths wrapping
  1153. + */
  1154. +
  1155. +void __overflow2(int a, int b)
  1156. +{
  1157. + if(a < 0 || b < 0)
  1158. + pm_error("object too large");
  1159. + if(b == 0)
  1160. + return;
  1161. + if(a > INT_MAX / b)
  1162. + pm_error("object too large");
  1163. +}
  1164. +
  1165. +void overflow3(int a, int b, int c)
  1166. +{
  1167. + overflow2(a,b);
  1168. + overflow2(a*b, c);
  1169. +}
  1170. +
  1171. +void overflow_add(int a, int b)
  1172. +{
  1173. + if( a > INT_MAX - b)
  1174. + pm_error("object too large");
  1175. +}
  1176. +
  1177. +void *malloc2(int a, int b)
  1178. +{
  1179. + overflow2(a, b);
  1180. + if(a*b == 0)
  1181. + pm_error("Zero byte allocation");
  1182. + return malloc(a*b);
  1183. +}
  1184. +
  1185. +void *malloc3(int a, int b, int c)
  1186. +{
  1187. + overflow3(a, b, c);
  1188. + if(a*b*c == 0)
  1189. + pm_error("Zero byte allocation");
  1190. + return malloc(a*b*c);
  1191. +}
  1192. +
  1193. +void *realloc2(void * a, int b, int c)
  1194. +{
  1195. + overflow2(b, c);
  1196. + if(b*c == 0)
  1197. + pm_error("Zero byte allocation");
  1198. + return realloc(a, b*c);
  1199. +}
  1200. diff -up netpbm-10.58.01/lib/pm.h.security-code netpbm-10.58.01/lib/pm.h
  1201. --- netpbm-10.58.01/lib/pm.h.security-code 2012-04-09 15:31:38.000000000 +0200
  1202. +++ netpbm-10.58.01/lib/pm.h 2012-04-09 15:40:03.229619464 +0200
  1203. @@ -432,4 +432,11 @@ pm_parse_height(const char * const arg);
  1204. #endif
  1205. +void *malloc2(int, int);
  1206. +void *malloc3(int, int, int);
  1207. +#define overflow2(a,b) __overflow2(a,b)
  1208. +void __overflow2(int, int);
  1209. +void overflow3(int, int, int);
  1210. +void overflow_add(int, int);
  1211. +
  1212. #endif
  1213. diff -up netpbm-10.58.01/other/pnmcolormap.c.security-code netpbm-10.58.01/other/pnmcolormap.c
  1214. --- netpbm-10.58.01/other/pnmcolormap.c.security-code 2012-04-09 15:31:32.000000000 +0200
  1215. +++ netpbm-10.58.01/other/pnmcolormap.c 2012-04-09 15:40:03.230619451 +0200
  1216. @@ -840,6 +840,7 @@ colormapToSquare(struct pam * const pamP
  1217. pamP->width = intsqrt;
  1218. else
  1219. pamP->width = intsqrt + 1;
  1220. + overflow_add(intsqrt, 1);
  1221. }
  1222. {
  1223. unsigned int const intQuotient = colormap.size / pamP->width;
  1224. diff -up netpbm-10.58.01/urt/README.security-code netpbm-10.58.01/urt/README
  1225. --- netpbm-10.58.01/urt/README.security-code 2012-04-09 15:31:45.000000000 +0200
  1226. +++ netpbm-10.58.01/urt/README 2012-04-09 15:40:03.231619438 +0200
  1227. @@ -18,3 +18,8 @@ in its initializer in the original. But
  1228. defines stdout as a variable, so that wouldn't compile. So I changed
  1229. it to NULL and added a line to rle_hdr_init to set that field to
  1230. 'stdout' dynamically. 2000.06.02 BJH.
  1231. +
  1232. +Redid the code to check for maths overflows and other crawly horrors.
  1233. +Removed pipe through and compress support (unsafe)
  1234. +
  1235. +Alan Cox <alan@redhat.com>
  1236. diff -up netpbm-10.58.01/urt/rle_addhist.c.security-code netpbm-10.58.01/urt/rle_addhist.c
  1237. --- netpbm-10.58.01/urt/rle_addhist.c.security-code 2012-04-09 15:31:45.000000000 +0200
  1238. +++ netpbm-10.58.01/urt/rle_addhist.c 2012-04-09 15:40:03.231619438 +0200
  1239. @@ -14,6 +14,8 @@
  1240. * If you modify this software, you should include a notice giving the
  1241. * name of the person performing the modification, the date of modification,
  1242. * and the reason for such modification.
  1243. + *
  1244. + * 2002-12-19: Fix maths wrapping bugs. Alan Cox <alan@redhat.com>
  1245. */
  1246. /*
  1247. * rle_addhist.c - Add to the HISTORY comment in header
  1248. @@ -71,13 +73,19 @@ rle_addhist(char * argv[],
  1249. return;
  1250. length = 0;
  1251. - for (i = 0; argv[i]; ++i)
  1252. + for (i = 0; argv[i]; ++i) {
  1253. + overflow_add(length, strlen(argv[i]));
  1254. + overflow_add(length+1, strlen(argv[i]));
  1255. length += strlen(argv[i]) +1; /* length of each arg plus space. */
  1256. + }
  1257. time(&temp);
  1258. timedate = ctime(&temp);
  1259. length += strlen(timedate); /* length of date and time in ASCII. */
  1260. + overflow_add(strlen(padding), 4);
  1261. + overflow_add(strlen(histoire), strlen(padding) + 4);
  1262. + overflow_add(length, strlen(histoire) + strlen(padding) + 4);
  1263. length += strlen(padding) + 3 + strlen(histoire) + 1;
  1264. /* length of padding, "on " and length of history name plus "="*/
  1265. if (in_hdr) /* if we are interested in the old comments... */
  1266. @@ -85,9 +93,12 @@ rle_addhist(char * argv[],
  1267. else
  1268. old = NULL;
  1269. - if (old && *old)
  1270. + if (old && *old) {
  1271. + overflow_add(length, strlen(old));
  1272. length += strlen(old); /* add length if there. */
  1273. + }
  1274. + overflow_add(length, 1);
  1275. ++length; /*Cater for the null. */
  1276. MALLOCARRAY(newc, length);
  1277. diff -up netpbm-10.58.01/urt/rle_getrow.c.security-code netpbm-10.58.01/urt/rle_getrow.c
  1278. --- netpbm-10.58.01/urt/rle_getrow.c.security-code 2012-04-09 15:31:45.000000000 +0200
  1279. +++ netpbm-10.58.01/urt/rle_getrow.c 2012-04-09 15:40:03.232619426 +0200
  1280. @@ -17,6 +17,8 @@
  1281. *
  1282. * Modified at BRL 16-May-88 by Mike Muuss to avoid Alliant STDC desire
  1283. * to have all "void" functions so declared.
  1284. + *
  1285. + * 2002-12-19: Fix maths wrapping bugs. Alan Cox <alan@redhat.com>
  1286. */
  1287. /*
  1288. * rle_getrow.c - Read an RLE file in.
  1289. @@ -168,6 +170,7 @@ rle_get_setup(rle_hdr * const the_hdr) {
  1290. register char * cp;
  1291. VAXSHORT( comlen, infile ); /* get comment length */
  1292. + overflow_add(comlen, 1);
  1293. evenlen = (comlen + 1) & ~1; /* make it even */
  1294. if ( evenlen )
  1295. {
  1296. diff -up netpbm-10.58.01/urt/rle_hdr.c.security-code netpbm-10.58.01/urt/rle_hdr.c
  1297. --- netpbm-10.58.01/urt/rle_hdr.c.security-code 2012-04-09 15:31:45.000000000 +0200
  1298. +++ netpbm-10.58.01/urt/rle_hdr.c 2012-04-09 15:40:03.233619414 +0200
  1299. @@ -14,6 +14,8 @@
  1300. * If you modify this software, you should include a notice giving the
  1301. * name of the person performing the modification, the date of modification,
  1302. * and the reason for such modification.
  1303. + *
  1304. + * 2002-12-19: Fix maths wrapping bugs. Alan Cox <alan@redhat.com>
  1305. */
  1306. /*
  1307. * rle_hdr.c - Functions to manipulate rle_hdr structures.
  1308. @@ -80,7 +82,10 @@ int img_num;
  1309. /* Fill in with copies of the strings. */
  1310. if ( the_hdr->cmd != pgmname )
  1311. {
  1312. - char *tmp = (char *)malloc( strlen( pgmname ) + 1 );
  1313. + char *tmp ;
  1314. +
  1315. + overflow_add(strlen(pgmname), 1);
  1316. + tmp = malloc( strlen( pgmname ) + 1 );
  1317. RLE_CHECK_ALLOC( pgmname, tmp, 0 );
  1318. strcpy( tmp, pgmname );
  1319. the_hdr->cmd = tmp;
  1320. @@ -88,7 +93,9 @@ int img_num;
  1321. if ( the_hdr->file_name != fname )
  1322. {
  1323. - char *tmp = (char *)malloc( strlen( fname ) + 1 );
  1324. + char *tmp;
  1325. + overflow_add(strlen(fname), 1);
  1326. + tmp = malloc( strlen( fname ) + 1 );
  1327. RLE_CHECK_ALLOC( pgmname, tmp, 0 );
  1328. strcpy( tmp, fname );
  1329. the_hdr->file_name = tmp;
  1330. @@ -153,6 +160,7 @@ rle_hdr *from_hdr, *to_hdr;
  1331. if ( to_hdr->bg_color )
  1332. {
  1333. int size = to_hdr->ncolors * sizeof(int);
  1334. + overflow2(to_hdr->ncolors, sizeof(int));
  1335. to_hdr->bg_color = (int *)malloc( size );
  1336. RLE_CHECK_ALLOC( to_hdr->cmd, to_hdr->bg_color, "background color" );
  1337. memcpy( to_hdr->bg_color, from_hdr->bg_color, size );
  1338. @@ -161,7 +169,7 @@ rle_hdr *from_hdr, *to_hdr;
  1339. if ( to_hdr->cmap )
  1340. {
  1341. int size = to_hdr->ncmap * (1 << to_hdr->cmaplen) * sizeof(rle_map);
  1342. - to_hdr->cmap = (rle_map *)malloc( size );
  1343. + to_hdr->cmap = (rle_map *)malloc3( to_hdr->ncmap, 1<<to_hdr->cmaplen, sizeof(rle_map));
  1344. RLE_CHECK_ALLOC( to_hdr->cmd, to_hdr->cmap, "color map" );
  1345. memcpy( to_hdr->cmap, from_hdr->cmap, size );
  1346. }
  1347. @@ -174,11 +182,16 @@ rle_hdr *from_hdr, *to_hdr;
  1348. int size = 0;
  1349. CONST_DECL char **cp;
  1350. for ( cp=to_hdr->comments; *cp; cp++ )
  1351. + {
  1352. + overflow_add(size, 1);
  1353. size++; /* Count the comments. */
  1354. + }
  1355. /* Check if there are really any comments. */
  1356. if ( size )
  1357. {
  1358. + overflow_add(size, 1);
  1359. size++; /* Copy the NULL pointer, too. */
  1360. + overflow2(size, sizeof(char *));
  1361. size *= sizeof(char *);
  1362. to_hdr->comments = (CONST_DECL char **)malloc( size );
  1363. RLE_CHECK_ALLOC( to_hdr->cmd, to_hdr->comments, "comments" );
  1364. diff -up netpbm-10.58.01/urt/rle.h.security-code netpbm-10.58.01/urt/rle.h
  1365. --- netpbm-10.58.01/urt/rle.h.security-code 2012-04-09 15:31:45.000000000 +0200
  1366. +++ netpbm-10.58.01/urt/rle.h 2012-04-09 15:40:03.233619414 +0200
  1367. @@ -14,6 +14,9 @@
  1368. * If you modify this software, you should include a notice giving the
  1369. * name of the person performing the modification, the date of modification,
  1370. * and the reason for such modification.
  1371. + *
  1372. + * 2002-12-19: Fix maths wrapping bugs. Alan Cox <alan@redhat.com>
  1373. + * Header declarations needed
  1374. */
  1375. /*
  1376. * rle.h - Global declarations for Utah Raster Toolkit RLE programs.
  1377. @@ -160,6 +163,17 @@ rle_hdr /* End of typedef. *
  1378. */
  1379. extern rle_hdr rle_dflt_hdr;
  1380. +/*
  1381. + * Provided by pm library
  1382. + */
  1383. +
  1384. +extern void overflow_add(int, int);
  1385. +#define overflow2(a,b) __overflow2(a,b)
  1386. +extern void __overflow2(int, int);
  1387. +extern void overflow3(int, int, int);
  1388. +extern void *malloc2(int, int);
  1389. +extern void *malloc3(int, int, int);
  1390. +extern void *realloc2(void *, int, int);
  1391. /* Declare RLE library routines. */
  1392. diff -up netpbm-10.58.01/urt/rle_open_f.c.security-code netpbm-10.58.01/urt/rle_open_f.c
  1393. --- netpbm-10.58.01/urt/rle_open_f.c.security-code 2012-04-09 15:31:45.000000000 +0200
  1394. +++ netpbm-10.58.01/urt/rle_open_f.c 2012-04-09 15:40:03.234619402 +0200
  1395. @@ -163,65 +163,7 @@ dealWithSubprocess(const char * const f
  1396. FILE ** const fpP,
  1397. bool * const noSubprocessP,
  1398. const char ** const errorP) {
  1399. -
  1400. -#ifdef NO_OPEN_PIPES
  1401. *noSubprocessP = TRUE;
  1402. -#else
  1403. - const char *cp;
  1404. -
  1405. - reapChildren(catchingChildrenP, pids);
  1406. -
  1407. - /* Real file, not stdin or stdout. If name ends in ".Z",
  1408. - * pipe from/to un/compress (depending on r/w mode).
  1409. - *
  1410. - * If it starts with "|", popen that command.
  1411. - */
  1412. -
  1413. - cp = file_name + strlen(file_name) - 2;
  1414. - /* Pipe case. */
  1415. - if (file_name[0] == '|') {
  1416. - pid_t thepid; /* PID from my_popen */
  1417. -
  1418. - *noSubprocessP = FALSE;
  1419. -
  1420. - *fpP = my_popen(file_name + 1, mode, &thepid);
  1421. - if (*fpP == NULL)
  1422. - *errorP = "%s: can't invoke <<%s>> for %s: ";
  1423. - else {
  1424. - /* One more child to catch, eventually. */
  1425. - if (*catchingChildrenP < MAX_CHILDREN)
  1426. - pids[(*catchingChildrenP)++] = thepid;
  1427. - }
  1428. - } else if (cp > file_name && *cp == '.' && *(cp + 1) == 'Z' ) {
  1429. - /* Compress case. */
  1430. - pid_t thepid; /* PID from my_popen. */
  1431. - const char * command;
  1432. -
  1433. - *noSubprocessP = FALSE;
  1434. -
  1435. - if (*mode == 'w')
  1436. - pm_asprintf(&command, "compress > %s", file_name);
  1437. - else if (*mode == 'a')
  1438. - pm_asprintf(&command, "compress >> %s", file_name);
  1439. - else
  1440. - pm_asprintf(&command, "compress -d < %s", file_name);
  1441. -
  1442. - *fpP = my_popen(command, mode, &thepid);
  1443. -
  1444. - if (*fpP == NULL)
  1445. - *errorP = "%s: can't invoke 'compress' program, "
  1446. - "trying to open %s for %s";
  1447. - else {
  1448. - /* One more child to catch, eventually. */
  1449. - if (*catchingChildrenP < MAX_CHILDREN)
  1450. - pids[(*catchingChildrenP)++] = thepid;
  1451. - }
  1452. - pm_strfree(command);
  1453. - } else {
  1454. - *noSubprocessP = TRUE;
  1455. - *errorP = NULL;
  1456. - }
  1457. -#endif
  1458. }
  1459. diff -up netpbm-10.58.01/urt/rle_putcom.c.security-code netpbm-10.58.01/urt/rle_putcom.c
  1460. --- netpbm-10.58.01/urt/rle_putcom.c.security-code 2012-04-09 15:31:45.000000000 +0200
  1461. +++ netpbm-10.58.01/urt/rle_putcom.c 2012-04-09 15:40:03.234619402 +0200
  1462. @@ -14,6 +14,8 @@
  1463. * If you modify this software, you should include a notice giving the
  1464. * name of the person performing the modification, the date of modification,
  1465. * and the reason for such modification.
  1466. + *
  1467. + * 2002-12-19: Fix maths wrapping bugs. Alan Cox <alan@redhat.com>
  1468. */
  1469. /*
  1470. * rle_putcom.c - Add a picture comment to the header struct.
  1471. @@ -98,12 +100,14 @@ rle_putcom(const char * const value,
  1472. const char * v;
  1473. const char ** old_comments;
  1474. int i;
  1475. - for (i = 2, cp = the_hdr->comments; *cp != NULL; ++i, ++cp)
  1476. + for (i = 2, cp = the_hdr->comments; *cp != NULL; ++i, ++cp) {
  1477. + overflow_add(i, 1);
  1478. if (match(value, *cp) != NULL) {
  1479. v = *cp;
  1480. *cp = value;
  1481. return v;
  1482. }
  1483. + }
  1484. /* Not found */
  1485. /* Can't realloc because somebody else might be pointing to this
  1486. * comments block. Of course, if this were true, then the
  1487. diff -up netpbm-10.58.01/urt/Runput.c.security-code netpbm-10.58.01/urt/Runput.c
  1488. --- netpbm-10.58.01/urt/Runput.c.security-code 2012-04-09 15:31:45.000000000 +0200
  1489. +++ netpbm-10.58.01/urt/Runput.c 2012-04-09 15:40:03.235619390 +0200
  1490. @@ -17,6 +17,8 @@
  1491. *
  1492. * Modified at BRL 16-May-88 by Mike Muuss to avoid Alliant STDC desire
  1493. * to have all "void" functions so declared.
  1494. + *
  1495. + * 2002-12-19: Fix maths wrapping bugs. Alan Cox <alan@redhat.com>
  1496. */
  1497. /*
  1498. * Runput.c - General purpose Run Length Encoding.
  1499. @@ -202,9 +204,11 @@ RunSetup(rle_hdr * the_hdr)
  1500. if ( the_hdr->background != 0 )
  1501. {
  1502. register int i;
  1503. - register rle_pixel *background =
  1504. - (rle_pixel *)malloc( (unsigned)(the_hdr->ncolors + 1) );
  1505. + register rle_pixel *background;
  1506. register int *bg_color;
  1507. +
  1508. + overflow_add(the_hdr->ncolors,1);
  1509. + background = (rle_pixel *)malloc( (unsigned)(the_hdr->ncolors + 1) );
  1510. /*
  1511. * If even number of bg color bytes, put out one more to get to
  1512. * 16 bit boundary.
  1513. @@ -224,7 +228,7 @@ RunSetup(rle_hdr * the_hdr)
  1514. /* Big-endian machines are harder */
  1515. register int i, nmap = (1 << the_hdr->cmaplen) *
  1516. the_hdr->ncmap;
  1517. - register char *h_cmap = (char *)malloc( nmap * 2 );
  1518. + register char *h_cmap = (char *)malloc2( nmap, 2 );
  1519. if ( h_cmap == NULL )
  1520. {
  1521. fprintf( stderr,
  1522. diff -up netpbm-10.58.01/urt/scanargs.c.security-code netpbm-10.58.01/urt/scanargs.c
  1523. --- netpbm-10.58.01/urt/scanargs.c.security-code 2012-04-09 15:31:45.000000000 +0200
  1524. +++ netpbm-10.58.01/urt/scanargs.c 2012-04-09 15:40:03.235619390 +0200
  1525. @@ -38,6 +38,8 @@
  1526. *
  1527. * Modified at BRL 16-May-88 by Mike Muuss to avoid Alliant STDC desire
  1528. * to have all "void" functions so declared.
  1529. + *
  1530. + * 2002-12-19: Fix maths wrapping bugs. Alan Cox <alan@redhat.com>
  1531. */
  1532. #include <stdio.h>
  1533. @@ -63,8 +65,8 @@ typedef int *ptr;
  1534. /*
  1535. * Storage allocation macros
  1536. */
  1537. -#define NEW( type, cnt ) (type *) malloc( (cnt) * sizeof( type ) )
  1538. -#define RENEW( type, ptr, cnt ) (type *) realloc( ptr, (cnt) * sizeof( type ) )
  1539. +#define NEW( type, cnt ) (type *) malloc2( (cnt) , sizeof( type ) )
  1540. +#define RENEW( type, ptr, cnt ) (type *) realloc2( ptr, (cnt), sizeof( type ) )
  1541. static CONST_DECL char * prformat( CONST_DECL char *, int );
  1542. static int isnum( CONST_DECL char *, int, int );