OLD | NEW |
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 "printing/pdf_metafile_cg_mac.h" | 5 #include "printing/pdf_metafile_cg_mac.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/mac/mac_util.h" | 12 #include "base/mac/mac_util.h" |
13 #include "base/mac/scoped_cftyperef.h" | 13 #include "base/mac/scoped_cftyperef.h" |
| 14 #include "base/numerics/safe_conversions.h" |
14 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
15 #include "ui/gfx/geometry/rect.h" | 16 #include "ui/gfx/geometry/rect.h" |
16 #include "ui/gfx/geometry/size.h" | 17 #include "ui/gfx/geometry/size.h" |
17 | 18 |
18 using base::ScopedCFTypeRef; | 19 using base::ScopedCFTypeRef; |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 // Rotate a page by |num_rotations| * 90 degrees, counter-clockwise. | 23 // Rotate a page by |num_rotations| * 90 degrees, counter-clockwise. |
23 void RotatePage(CGContextRef context, const CGRect rect, int num_rotations) { | 24 void RotatePage(CGContextRef context, const CGRect rect, int num_rotations) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 context_.reset(CGPDFContextCreate(pdf_consumer, nullptr, nullptr)); | 81 context_.reset(CGPDFContextCreate(pdf_consumer, nullptr, nullptr)); |
81 if (!context_.get()) { | 82 if (!context_.get()) { |
82 LOG(ERROR) << "Failed to create pdf context for metafile"; | 83 LOG(ERROR) << "Failed to create pdf context for metafile"; |
83 pdf_data_.reset(); | 84 pdf_data_.reset(); |
84 } | 85 } |
85 | 86 |
86 return true; | 87 return true; |
87 } | 88 } |
88 | 89 |
89 bool PdfMetafileCg::InitFromData(const void* src_buffer, | 90 bool PdfMetafileCg::InitFromData(const void* src_buffer, |
90 uint32_t src_buffer_size) { | 91 size_t src_buffer_size) { |
91 DCHECK(!context_.get()); | 92 DCHECK(!context_.get()); |
92 DCHECK(!pdf_data_.get()); | 93 DCHECK(!pdf_data_.get()); |
93 | 94 |
94 if (!src_buffer || src_buffer_size == 0) { | 95 if (!src_buffer || !src_buffer_size) |
95 return false; | 96 return false; |
96 } | 97 |
| 98 if (!base::IsValueInRangeForNumericType<CFIndex>(src_buffer_size)) |
| 99 return false; |
97 | 100 |
98 pdf_data_.reset(CFDataCreateMutable(kCFAllocatorDefault, src_buffer_size)); | 101 pdf_data_.reset(CFDataCreateMutable(kCFAllocatorDefault, src_buffer_size)); |
99 CFDataAppendBytes(pdf_data_, static_cast<const UInt8*>(src_buffer), | 102 CFDataAppendBytes(pdf_data_, static_cast<const UInt8*>(src_buffer), |
100 src_buffer_size); | 103 src_buffer_size); |
101 | 104 |
102 return true; | 105 return true; |
103 } | 106 } |
104 | 107 |
105 void PdfMetafileCg::StartPage(const gfx::Size& page_size, | 108 void PdfMetafileCg::StartPage(const gfx::Size& page_size, |
106 const gfx::Rect& content_area, | 109 const gfx::Rect& content_area, |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 | 292 |
290 if (!pdf_doc_.get()) { | 293 if (!pdf_doc_.get()) { |
291 ScopedCFTypeRef<CGDataProviderRef> pdf_data_provider( | 294 ScopedCFTypeRef<CGDataProviderRef> pdf_data_provider( |
292 CGDataProviderCreateWithCFData(pdf_data_)); | 295 CGDataProviderCreateWithCFData(pdf_data_)); |
293 pdf_doc_.reset(CGPDFDocumentCreateWithProvider(pdf_data_provider)); | 296 pdf_doc_.reset(CGPDFDocumentCreateWithProvider(pdf_data_provider)); |
294 } | 297 } |
295 return pdf_doc_.get(); | 298 return pdf_doc_.get(); |
296 } | 299 } |
297 | 300 |
298 } // namespace printing | 301 } // namespace printing |
OLD | NEW |