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

Side by Side Diff: pdf/pdfium/pdfium_engine.cc

Issue 599373003: Memory allocation for WriteInto is not proper. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 2 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 | pdf/pdfium/pdfium_page.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium 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 #include "pdf/pdfium/pdfium_engine.h" 5 #include "pdf/pdfium/pdfium_engine.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 3382 matching lines...) Expand 10 before | Expand all | Expand 10 after
3393 3393
3394 // A temporary hack. PDFs generated by Cairo (used by Chrome OS to generate 3394 // A temporary hack. PDFs generated by Cairo (used by Chrome OS to generate
3395 // a PDF output from a webpage) result in very large metafiles and the 3395 // a PDF output from a webpage) result in very large metafiles and the
3396 // rendering using FPDF_RenderPage is incorrect. In this case, render as a 3396 // rendering using FPDF_RenderPage is incorrect. In this case, render as a
3397 // bitmap. Note that this code does not kick in for PDFs printed from Chrome 3397 // bitmap. Note that this code does not kick in for PDFs printed from Chrome
3398 // because in that case we create a temp PDF first before printing and this 3398 // because in that case we create a temp PDF first before printing and this
3399 // temp PDF does not have a creator string that starts with "cairo". 3399 // temp PDF does not have a creator string that starts with "cairo".
3400 base::string16 creator; 3400 base::string16 creator;
3401 size_t buffer_bytes = FPDF_GetMetaText(doc, "Creator", NULL, 0); 3401 size_t buffer_bytes = FPDF_GetMetaText(doc, "Creator", NULL, 0);
3402 if (buffer_bytes > 1) { 3402 if (buffer_bytes > 1) {
3403 FPDF_GetMetaText(doc, "Creator", WriteInto(&creator, buffer_bytes), 3403 FPDF_GetMetaText(
3404 buffer_bytes); 3404 doc, "Creator", WriteInto(&creator, buffer_bytes + 1), buffer_bytes);
3405 } 3405 }
3406 bool use_bitmap = false; 3406 bool use_bitmap = false;
3407 if (StartsWith(creator, L"cairo", false)) 3407 if (StartsWith(creator, L"cairo", false))
3408 use_bitmap = true; 3408 use_bitmap = true;
3409 3409
3410 // Another temporary hack. Some PDFs seems to render very slowly if 3410 // Another temporary hack. Some PDFs seems to render very slowly if
3411 // FPDF_RenderPage is directly used on a printer DC. I suspect it is 3411 // FPDF_RenderPage is directly used on a printer DC. I suspect it is
3412 // because of the code to talk Postscript directly to the printer if 3412 // because of the code to talk Postscript directly to the printer if
3413 // the printer supports this. Need to discuss this with PDFium. For now, 3413 // the printer supports this. Need to discuss this with PDFium. For now,
3414 // render to a bitmap and then blit the bitmap to the DC if we have been 3414 // render to a bitmap and then blit the bitmap to the DC if we have been
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
3518 double* height) { 3518 double* height) {
3519 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL); 3519 FPDF_DOCUMENT doc = FPDF_LoadMemDocument(pdf_buffer, pdf_buffer_size, NULL);
3520 if (!doc) 3520 if (!doc)
3521 return false; 3521 return false;
3522 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0; 3522 bool success = FPDF_GetPageSizeByIndex(doc, page_number, width, height) != 0;
3523 FPDF_CloseDocument(doc); 3523 FPDF_CloseDocument(doc);
3524 return success; 3524 return success;
3525 } 3525 }
3526 3526
3527 } // namespace chrome_pdf 3527 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « no previous file | pdf/pdfium/pdfium_page.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698