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

Side by Side Diff: core/src/fxcodec/codec/fx_codec_flate.cpp

Issue 1124563002: Fix a couple of divide by zero crashes in PNG/TIFF predictors. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: rebase Created 5 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 | « no previous file | 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 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../../../third_party/base/nonstd_unique_ptr.h"
8 #include "../../../include/fxcodec/fx_codec.h"
7 #include "../../fx_zlib.h" 9 #include "../../fx_zlib.h"
8 #include "../../../include/fxcodec/fx_codec.h"
9 #include "codec_int.h" 10 #include "codec_int.h"
11
10 extern "C" 12 extern "C"
11 { 13 {
12 static void* my_alloc_func (void* opaque, unsigned int items, unsigned int s ize) 14 static void* my_alloc_func (void* opaque, unsigned int items, unsigned int s ize)
13 { 15 {
14 return FX_Alloc(FX_BYTE, items * size); 16 return FX_Alloc(FX_BYTE, items * size);
15 } 17 }
16 static void my_free_func (void* opaque, void* address) 18 static void my_free_func (void* opaque, void* address)
17 { 19 {
18 FX_Free(address); 20 FX_Free(address);
19 } 21 }
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 int pb = FXSYS_abs(p - b); 224 int pb = FXSYS_abs(p - b);
223 int pc = FXSYS_abs(p - c); 225 int pc = FXSYS_abs(p - c);
224 if (pa <= pb && pa <= pc) { 226 if (pa <= pb && pa <= pc) {
225 return (FX_BYTE)a; 227 return (FX_BYTE)a;
226 } 228 }
227 if (pb <= pc) { 229 if (pb <= pc) {
228 return (FX_BYTE)b; 230 return (FX_BYTE)b;
229 } 231 }
230 return (FX_BYTE)c; 232 return (FX_BYTE)c;
231 } 233 }
232 static void PNG_PredictorEncode(FX_LPBYTE& data_buf, FX_DWORD& data_size, int pr edictor, int Colors, int BitsPerComponent, int Columns) 234 static FX_BOOL PNG_PredictorEncode(FX_LPBYTE& data_buf, FX_DWORD& data_size,
235 int predictor, int Colors,
236 int BitsPerComponent, int Columns)
233 { 237 {
234 int BytesPerPixel = (Colors * BitsPerComponent + 7) / 8; 238 const int BytesPerPixel = (Colors * BitsPerComponent + 7) / 8;
235 int row_size = (Colors * BitsPerComponent * Columns + 7) / 8; 239 const int row_size = (Colors * BitsPerComponent * Columns + 7) / 8;
236 int row_count = (data_size + row_size - 1) / row_size; 240 if (row_size <= 0)
237 int last_row_size = data_size % row_size; 241 return FALSE;
242 const int row_count = (data_size + row_size - 1) / row_size;
243 const int last_row_size = data_size % row_size;
238 FX_LPBYTE dest_buf = FX_Alloc( FX_BYTE, (row_size + 1) * row_count); 244 FX_LPBYTE dest_buf = FX_Alloc( FX_BYTE, (row_size + 1) * row_count);
239 if (dest_buf == NULL) { 245 if (dest_buf == NULL)
240 return; 246 return FALSE;
241 }
242 int byte_cnt = 0; 247 int byte_cnt = 0;
243 FX_LPBYTE pSrcData = data_buf; 248 FX_LPBYTE pSrcData = data_buf;
244 FX_LPBYTE pDestData = dest_buf; 249 FX_LPBYTE pDestData = dest_buf;
245 for (int row = 0; row < row_count; row++) { 250 for (int row = 0; row < row_count; row++) {
246 if (predictor == 10) { 251 if (predictor == 10) {
247 pDestData[0] = 0; 252 pDestData[0] = 0;
248 int move_size = row_size; 253 int move_size = row_size;
249 if (move_size * (row + 1) > (int)data_size) { 254 if (move_size * (row + 1) > (int)data_size) {
250 move_size = data_size - (move_size * row); 255 move_size = data_size - (move_size * row);
251 } 256 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 break; 316 break;
312 } 317 }
313 byte_cnt++; 318 byte_cnt++;
314 } 319 }
315 pDestData += (row_size + 1); 320 pDestData += (row_size + 1);
316 pSrcData += row_size; 321 pSrcData += row_size;
317 } 322 }
318 FX_Free(data_buf); 323 FX_Free(data_buf);
319 data_buf = dest_buf; 324 data_buf = dest_buf;
320 data_size = (row_size + 1) * row_count - (last_row_size > 0 ? (row_size - la st_row_size) : 0); 325 data_size = (row_size + 1) * row_count - (last_row_size > 0 ? (row_size - la st_row_size) : 0);
326 return TRUE;
321 } 327 }
322 static void PNG_PredictLine(FX_LPBYTE pDestData, FX_LPCBYTE pSrcData, FX_LPCBYTE pLastLine, 328 static void PNG_PredictLine(FX_LPBYTE pDestData, FX_LPCBYTE pSrcData, FX_LPCBYTE pLastLine,
323 int bpc, int nColors, int nPixels) 329 int bpc, int nColors, int nPixels)
324 { 330 {
325 int row_size = (nPixels * bpc * nColors + 7) / 8; 331 int row_size = (nPixels * bpc * nColors + 7) / 8;
326 int BytesPerPixel = (bpc * nColors + 7) / 8; 332 int BytesPerPixel = (bpc * nColors + 7) / 8;
327 FX_BYTE tag = pSrcData[0]; 333 FX_BYTE tag = pSrcData[0];
328 if (tag == 0) { 334 if (tag == 0) {
329 FXSYS_memmove32(pDestData, pSrcData + 1, row_size); 335 FXSYS_memmove32(pDestData, pSrcData + 1, row_size);
330 return; 336 return;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 } 381 }
376 pDestData[byte] = raw_byte + PaethPredictor(left, up, upper_ left); 382 pDestData[byte] = raw_byte + PaethPredictor(left, up, upper_ left);
377 break; 383 break;
378 } 384 }
379 default: 385 default:
380 pDestData[byte] = raw_byte; 386 pDestData[byte] = raw_byte;
381 break; 387 break;
382 } 388 }
383 } 389 }
384 } 390 }
385 static void PNG_Predictor(FX_LPBYTE& data_buf, FX_DWORD& data_size, 391 static FX_BOOL PNG_Predictor(FX_LPBYTE& data_buf, FX_DWORD& data_size,
386 int Colors, int BitsPerComponent, int Columns) 392 int Colors, int BitsPerComponent, int Columns)
387 { 393 {
388 int BytesPerPixel = (Colors * BitsPerComponent + 7) / 8; 394 const int BytesPerPixel = (Colors * BitsPerComponent + 7) / 8;
389 int row_size = (Colors * BitsPerComponent * Columns + 7) / 8; 395 const int row_size = (Colors * BitsPerComponent * Columns + 7) / 8;
390 int row_count = (data_size + row_size) / (row_size + 1); 396 if (row_size <= 0)
391 int last_row_size = data_size % (row_size + 1); 397 return FALSE;
398 const int row_count = (data_size + row_size) / (row_size + 1);
399 const int last_row_size = data_size % (row_size + 1);
392 FX_LPBYTE dest_buf = FX_Alloc( FX_BYTE, row_size * row_count); 400 FX_LPBYTE dest_buf = FX_Alloc( FX_BYTE, row_size * row_count);
393 if (dest_buf == NULL) { 401 if (dest_buf == NULL)
394 return; 402 return FALSE;
395 }
396 int byte_cnt = 0; 403 int byte_cnt = 0;
397 FX_LPBYTE pSrcData = data_buf; 404 FX_LPBYTE pSrcData = data_buf;
398 FX_LPBYTE pDestData = dest_buf; 405 FX_LPBYTE pDestData = dest_buf;
399 for (int row = 0; row < row_count; row ++) { 406 for (int row = 0; row < row_count; row ++) {
400 FX_BYTE tag = pSrcData[0]; 407 FX_BYTE tag = pSrcData[0];
401 byte_cnt++; 408 byte_cnt++;
402 if (tag == 0) { 409 if (tag == 0) {
403 int move_size = row_size; 410 int move_size = row_size;
404 if ((row + 1) * (move_size + 1) > (int)data_size) { 411 if ((row + 1) * (move_size + 1) > (int)data_size) {
405 move_size = last_row_size - 1; 412 move_size = last_row_size - 1;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 break; 469 break;
463 } 470 }
464 byte_cnt++; 471 byte_cnt++;
465 } 472 }
466 pSrcData += row_size + 1; 473 pSrcData += row_size + 1;
467 pDestData += row_size; 474 pDestData += row_size;
468 } 475 }
469 FX_Free(data_buf); 476 FX_Free(data_buf);
470 data_buf = dest_buf; 477 data_buf = dest_buf;
471 data_size = row_size * row_count - (last_row_size > 0 ? (row_size + 1 - last _row_size) : 0); 478 data_size = row_size * row_count - (last_row_size > 0 ? (row_size + 1 - last _row_size) : 0);
479 return TRUE;
472 } 480 }
473 static void TIFF_PredictorEncodeLine(FX_LPBYTE dest_buf, int row_size, int BitsP erComponent, int Colors, int Columns) 481 static void TIFF_PredictorEncodeLine(FX_LPBYTE dest_buf, int row_size, int BitsP erComponent, int Colors, int Columns)
474 { 482 {
475 int BytesPerPixel = BitsPerComponent * Colors / 8; 483 int BytesPerPixel = BitsPerComponent * Colors / 8;
476 if (BitsPerComponent < 8) { 484 if (BitsPerComponent < 8) {
477 FX_BYTE mask = 0x01; 485 FX_BYTE mask = 0x01;
478 if (BitsPerComponent == 2) { 486 if (BitsPerComponent == 2) {
479 mask = 0x03; 487 mask = 0x03;
480 } else if (BitsPerComponent == 4) { 488 } else if (BitsPerComponent == 4) {
481 mask = 0x0F; 489 mask = 0x0F;
(...skipping 18 matching lines...) Expand all
500 } 508 }
501 } else { 509 } else {
502 for (int i = row_size - BytesPerPixel; i >= BytesPerPixel; i -= BytesPer Pixel) { 510 for (int i = row_size - BytesPerPixel; i >= BytesPerPixel; i -= BytesPer Pixel) {
503 FX_WORD pixel = (dest_buf[i] << 8) | dest_buf[i + 1]; 511 FX_WORD pixel = (dest_buf[i] << 8) | dest_buf[i + 1];
504 pixel -= (dest_buf[i - BytesPerPixel] << 8) | dest_buf[i - BytesPerP ixel + 1]; 512 pixel -= (dest_buf[i - BytesPerPixel] << 8) | dest_buf[i - BytesPerP ixel + 1];
505 dest_buf[i] = pixel >> 8; 513 dest_buf[i] = pixel >> 8;
506 dest_buf[i + 1] = (FX_BYTE)pixel; 514 dest_buf[i + 1] = (FX_BYTE)pixel;
507 } 515 }
508 } 516 }
509 } 517 }
510 static void TIFF_PredictorEncode(FX_LPBYTE& data_buf, FX_DWORD& data_size, 518 static FX_BOOL TIFF_PredictorEncode(FX_LPBYTE& data_buf, FX_DWORD& data_size,
511 int Colors, int BitsPerComponent, int Columns) 519 int Colors, int BitsPerComponent, int Column s)
512 { 520 {
513 int row_size = (Colors * BitsPerComponent * Columns + 7) / 8; 521 int row_size = (Colors * BitsPerComponent * Columns + 7) / 8;
514 int row_count = (data_size + row_size - 1) / row_size; 522 if (row_size == 0)
515 int last_row_size = data_size % row_size; 523 return FALSE;
524 const int row_count = (data_size + row_size - 1) / row_size;
525 const int last_row_size = data_size % row_size;
516 for (int row = 0; row < row_count; row++) { 526 for (int row = 0; row < row_count; row++) {
517 FX_LPBYTE scan_line = data_buf + row * row_size; 527 FX_LPBYTE scan_line = data_buf + row * row_size;
518 if ((row + 1) * row_size > (int)data_size) { 528 if ((row + 1) * row_size > (int)data_size) {
519 row_size = last_row_size; 529 row_size = last_row_size;
520 } 530 }
521 TIFF_PredictorEncodeLine(scan_line, row_size, BitsPerComponent, Colors, Columns); 531 TIFF_PredictorEncodeLine(scan_line, row_size, BitsPerComponent, Colors, Columns);
522 } 532 }
533 return TRUE;
523 } 534 }
524 static void TIFF_PredictLine(FX_LPBYTE dest_buf, int row_size, int BitsPerCompon ent, int Colors, int Columns) 535 static void TIFF_PredictLine(FX_LPBYTE dest_buf, int row_size, int BitsPerCompon ent, int Colors, int Columns)
525 { 536 {
526 if (BitsPerComponent == 1) { 537 if (BitsPerComponent == 1) {
527 int row_bits = FX_MIN(BitsPerComponent * Colors * Columns, row_size * 8) ; 538 int row_bits = FX_MIN(BitsPerComponent * Colors * Columns, row_size * 8) ;
528 int index_pre = 0; 539 int index_pre = 0;
529 int col_pre = 0; 540 int col_pre = 0;
530 for(int i = 1; i < row_bits; i ++) { 541 for(int i = 1; i < row_bits; i ++) {
531 int col = i % 8; 542 int col = i % 8;
532 int index = i / 8; 543 int index = i / 8;
(...skipping 14 matching lines...) Expand all
547 pixel += (dest_buf[i] << 8) | dest_buf[i + 1]; 558 pixel += (dest_buf[i] << 8) | dest_buf[i + 1];
548 dest_buf[i] = pixel >> 8; 559 dest_buf[i] = pixel >> 8;
549 dest_buf[i + 1] = (FX_BYTE)pixel; 560 dest_buf[i + 1] = (FX_BYTE)pixel;
550 } 561 }
551 } else { 562 } else {
552 for (int i = BytesPerPixel; i < row_size; i ++) { 563 for (int i = BytesPerPixel; i < row_size; i ++) {
553 dest_buf[i] += dest_buf[i - BytesPerPixel]; 564 dest_buf[i] += dest_buf[i - BytesPerPixel];
554 } 565 }
555 } 566 }
556 } 567 }
557 static void TIFF_Predictor(FX_LPBYTE& data_buf, FX_DWORD& data_size, 568 static FX_BOOL TIFF_Predictor(FX_LPBYTE& data_buf, FX_DWORD& data_size,
558 int Colors, int BitsPerComponent, int Columns) 569 int Colors, int BitsPerComponent, int Columns)
559 { 570 {
560 int row_size = (Colors * BitsPerComponent * Columns + 7) / 8; 571 int row_size = (Colors * BitsPerComponent * Columns + 7) / 8;
561 int row_count = (data_size + row_size - 1) / row_size; 572 if (row_size == 0)
562 int last_row_size = data_size % row_size; 573 return FALSE;
574 const int row_count = (data_size + row_size - 1) / row_size;
575 const int last_row_size = data_size % row_size;
563 for (int row = 0; row < row_count; row ++) { 576 for (int row = 0; row < row_count; row ++) {
564 FX_LPBYTE scan_line = data_buf + row * row_size; 577 FX_LPBYTE scan_line = data_buf + row * row_size;
565 if ((row + 1) * row_size > (int)data_size) { 578 if ((row + 1) * row_size > (int)data_size) {
566 row_size = last_row_size; 579 row_size = last_row_size;
567 } 580 }
568 TIFF_PredictLine(scan_line, row_size, BitsPerComponent, Colors, Columns) ; 581 TIFF_PredictLine(scan_line, row_size, BitsPerComponent, Colors, Columns) ;
569 } 582 }
583 return TRUE;
570 } 584 }
571 class CCodec_FlateScanlineDecoder : public CCodec_ScanlineDecoder 585 class CCodec_FlateScanlineDecoder : public CCodec_ScanlineDecoder
572 { 586 {
573 public: 587 public:
574 CCodec_FlateScanlineDecoder(); 588 CCodec_FlateScanlineDecoder();
575 ~CCodec_FlateScanlineDecoder(); 589 ~CCodec_FlateScanlineDecoder();
576 FX_BOOL Create(FX_LPCBYTE src_buf, FX_DWORD src_size, int width, int height, int nComps, int bpc, 590 FX_BOOL Create(FX_LPCBYTE src_buf, FX_DWORD src_size, int width, int height, int nComps, int bpc,
577 int predictor, int Colors, int BitsPerComponent, int Colu mns); 591 int predictor, int Colors, int BitsPerComponent, int Colu mns);
578 virtual void Destroy() 592 virtual void Destroy()
579 { 593 {
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 int nComps, int bpc, int predictor, int Colors, int BitsPerComponent, in t Columns) 866 int nComps, int bpc, int predictor, int Colors, int BitsPerComponent, in t Columns)
853 { 867 {
854 CCodec_FlateScanlineDecoder* pDecoder = new CCodec_FlateScanlineDecoder; 868 CCodec_FlateScanlineDecoder* pDecoder = new CCodec_FlateScanlineDecoder;
855 pDecoder->Create(src_buf, src_size, width, height, nComps, bpc, predictor, C olors, BitsPerComponent, Columns); 869 pDecoder->Create(src_buf, src_size, width, height, nComps, bpc, predictor, C olors, BitsPerComponent, Columns);
856 return pDecoder; 870 return pDecoder;
857 } 871 }
858 FX_DWORD CCodec_FlateModule::FlateOrLZWDecode(FX_BOOL bLZW, const FX_BYTE* src_b uf, FX_DWORD src_size, FX_BOOL bEarlyChange, 872 FX_DWORD CCodec_FlateModule::FlateOrLZWDecode(FX_BOOL bLZW, const FX_BYTE* src_b uf, FX_DWORD src_size, FX_BOOL bEarlyChange,
859 int predictor, int Colors, int BitsPerComponent, int Columns, 873 int predictor, int Colors, int BitsPerComponent, int Columns,
860 FX_DWORD estimated_size, FX_LPBYTE& dest_buf, FX_DWORD& dest_size) 874 FX_DWORD estimated_size, FX_LPBYTE& dest_buf, FX_DWORD& dest_size)
861 { 875 {
862 CLZWDecoder* pDecoder = NULL;
863 dest_buf = NULL; 876 dest_buf = NULL;
864 FX_DWORD offset = 0; 877 FX_DWORD offset = 0;
865 int predictor_type = 0; 878 int predictor_type = 0;
866 if (predictor) { 879 if (predictor) {
867 if (predictor >= 10) { 880 if (predictor >= 10) {
868 predictor_type = 2; 881 predictor_type = 2;
869 } else if (predictor == 2) { 882 } else if (predictor == 2) {
870 predictor_type = 1; 883 predictor_type = 1;
871 } 884 }
872 } 885 }
873 if (bLZW) { 886 if (bLZW) {
874 pDecoder = new CLZWDecoder; 887 {
875 dest_size = (FX_DWORD) - 1; 888 nonstd::unique_ptr<CLZWDecoder> decoder(new CLZWDecoder);
876 offset = src_size; 889 dest_size = (FX_DWORD) - 1;
877 int err = pDecoder->Decode(NULL, dest_size, src_buf, offset, bEarlyChang e); 890 offset = src_size;
878 delete pDecoder; 891 int err = decoder->Decode(NULL, dest_size, src_buf, offset,
879 if (err || dest_size == 0 || dest_size + 1 < dest_size) { 892 bEarlyChange);
880 return (FX_DWORD) - 1; 893 if (err || dest_size == 0 || dest_size + 1 < dest_size) {
894 return -1;
895 }
881 } 896 }
882 pDecoder = new CLZWDecoder; 897 {
883 dest_buf = FX_Alloc( FX_BYTE, dest_size + 1); 898 nonstd::unique_ptr<CLZWDecoder> decoder(new CLZWDecoder);
884 if (dest_buf == NULL) { 899 dest_buf = FX_Alloc( FX_BYTE, dest_size + 1);
885 return -1; 900 if (dest_buf == NULL) {
901 return -1;
902 }
903 dest_buf[dest_size] = '\0';
904 decoder->Decode(dest_buf, dest_size, src_buf, offset, bEarlyChange);
886 } 905 }
887 dest_buf[dest_size] = '\0';
888 pDecoder->Decode(dest_buf, dest_size, src_buf, offset, bEarlyChange);
889 delete pDecoder;
890 } else { 906 } else {
891 FlateUncompress(src_buf, src_size, estimated_size, dest_buf, dest_size, offset); 907 FlateUncompress(src_buf, src_size, estimated_size, dest_buf, dest_size, offset);
892 } 908 }
893 if (predictor_type == 0) { 909 if (predictor_type == 0) {
894 return offset; 910 return offset;
895 } 911 }
912 FX_BOOL ret = TRUE;
896 if (predictor_type == 2) { 913 if (predictor_type == 2) {
897 PNG_Predictor(dest_buf, dest_size, Colors, BitsPerComponent, Columns); 914 ret = PNG_Predictor(dest_buf, dest_size, Colors, BitsPerComponent,
915 Columns);
898 } else if (predictor_type == 1) { 916 } else if (predictor_type == 1) {
899 TIFF_Predictor(dest_buf, dest_size, Colors, BitsPerComponent, Columns); 917 ret = TIFF_Predictor(dest_buf, dest_size, Colors, BitsPerComponent,
918 Columns);
900 } 919 }
901 return offset; 920 return ret ? offset : -1;
902 } 921 }
903 FX_BOOL CCodec_FlateModule::Encode(const FX_BYTE* src_buf, FX_DWORD src_size, 922 FX_BOOL CCodec_FlateModule::Encode(const FX_BYTE* src_buf, FX_DWORD src_size,
904 int predictor, int Colors, int BitsPerCompone nt, int Columns, 923 int predictor, int Colors, int BitsPerCompone nt, int Columns,
905 FX_LPBYTE& dest_buf, FX_DWORD& dest_size) 924 FX_LPBYTE& dest_buf, FX_DWORD& dest_size)
906 { 925 {
907 if (predictor != 2 && predictor < 10) { 926 if (predictor != 2 && predictor < 10) {
908 return Encode(src_buf, src_size, dest_buf, dest_size); 927 return Encode(src_buf, src_size, dest_buf, dest_size);
909 } 928 }
910 FX_BOOL ret = FALSE;
911 FX_LPBYTE pSrcBuf = NULL; 929 FX_LPBYTE pSrcBuf = NULL;
912 pSrcBuf = FX_Alloc(FX_BYTE, src_size); 930 pSrcBuf = FX_Alloc(FX_BYTE, src_size);
913 if (pSrcBuf == NULL) { 931 if (pSrcBuf == NULL) {
914 return FALSE; 932 return FALSE;
915 } 933 }
916 FXSYS_memcpy32(pSrcBuf, src_buf, src_size); 934 FXSYS_memcpy32(pSrcBuf, src_buf, src_size);
935 FX_BOOL ret = TRUE;
917 if (predictor == 2) { 936 if (predictor == 2) {
918 TIFF_PredictorEncode(pSrcBuf, src_size, Colors, BitsPerComponent, Column s); 937 ret = TIFF_PredictorEncode(pSrcBuf, src_size, Colors, BitsPerComponent,
938 Columns);
919 } else if (predictor >= 10) { 939 } else if (predictor >= 10) {
920 PNG_PredictorEncode(pSrcBuf, src_size, predictor, Colors, BitsPerCompone nt, Columns); 940 ret = PNG_PredictorEncode(pSrcBuf, src_size, predictor, Colors,
941 BitsPerComponent, Columns);
921 } 942 }
922 ret = Encode(pSrcBuf, src_size, dest_buf, dest_size); 943 if (ret)
944 ret = Encode(pSrcBuf, src_size, dest_buf, dest_size);
923 FX_Free(pSrcBuf); 945 FX_Free(pSrcBuf);
924 return ret; 946 return ret;
925 } 947 }
926 FX_BOOL CCodec_FlateModule::Encode(FX_LPCBYTE src_buf, FX_DWORD src_size, FX_LPB YTE& dest_buf, FX_DWORD& dest_size) 948 FX_BOOL CCodec_FlateModule::Encode(FX_LPCBYTE src_buf, FX_DWORD src_size, FX_LPB YTE& dest_buf, FX_DWORD& dest_size)
927 { 949 {
928 dest_size = src_size + src_size / 1000 + 12; 950 dest_size = src_size + src_size / 1000 + 12;
929 dest_buf = FX_Alloc( FX_BYTE, dest_size); 951 dest_buf = FX_Alloc( FX_BYTE, dest_size);
930 if (dest_buf == NULL) { 952 if (dest_buf == NULL) {
931 return FALSE; 953 return FALSE;
932 } 954 }
933 unsigned long temp_size = dest_size; 955 unsigned long temp_size = dest_size;
934 FPDFAPI_FlateCompress(dest_buf, &temp_size, src_buf, src_size); 956 FPDFAPI_FlateCompress(dest_buf, &temp_size, src_buf, src_size);
935 dest_size = (FX_DWORD)temp_size; 957 dest_size = (FX_DWORD)temp_size;
936 return TRUE; 958 return TRUE;
937 } 959 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698