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

Side by Side Diff: printing/page_range.cc

Issue 25651002: Fixed memory overflow caused by invalid input. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | printing/page_range_unittest.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/page_range.h" 5 #include "printing/page_range.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8
9 namespace {
10 const std::size_t kMaxNumberOfPages = 100000;
11 }
9 12
10 namespace printing { 13 namespace printing {
11 14
12 /* static */ 15 /* static */
13 std::vector<int> PageRange::GetPages(const PageRanges& ranges) { 16 std::vector<int> PageRange::GetPages(const PageRanges& ranges) {
17 // TODO(vitalybuka): crbug.com/95548 Remove this method as part fix.
14 std::set<int> pages; 18 std::set<int> pages;
15 for (unsigned i = 0; i < ranges.size(); ++i) { 19 for (unsigned i = 0; i < ranges.size(); ++i) {
16 const PageRange& range = ranges[i]; 20 const PageRange& range = ranges[i];
17 // Ranges are inclusive. 21 // Ranges are inclusive.
18 for (int i = range.from; i <= range.to; ++i) { 22 for (int i = range.from; i <= range.to; ++i) {
19 pages.insert(i); 23 pages.insert(i);
24 if (pages.size() >= kMaxNumberOfPages)
25 return std::vector<int>(pages.begin(), pages.end());
20 } 26 }
21 } 27 }
22 return std::vector<int>(pages.begin(), pages.end()); 28 return std::vector<int>(pages.begin(), pages.end());
23 } 29 }
24 30
25 } // namespace printing 31 } // namespace printing
OLDNEW
« no previous file with comments | « no previous file | printing/page_range_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698