diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-04-09 18:30:24 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-04-09 18:30:24 +0000 |
commit | 53894390dba2ec571bab75157ebe60d11171ed07 (patch) | |
tree | a2187a69fdc5167be060c621370a6c7c84ebf2e3 /core/fpdfapi/parser/cpdf_simple_parser.cpp | |
parent | d45f9980995af5c6e4c68e32df89d3cccb0231ef (diff) | |
download | pdfium-53894390dba2ec571bab75157ebe60d11171ed07.tar.xz |
Use pdfium::span<> in CFX_BitStream, CPDF_SimpleParser.
Get bounds checks in parsers automatically when using spans.
Change-Id: I71fbe7b838435d455376db2f89817d807a9cdcfd
Reviewed-on: https://pdfium-review.googlesource.com/29830
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fpdfapi/parser/cpdf_simple_parser.cpp')
-rw-r--r-- | core/fpdfapi/parser/cpdf_simple_parser.cpp | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/core/fpdfapi/parser/cpdf_simple_parser.cpp b/core/fpdfapi/parser/cpdf_simple_parser.cpp index 45ea0d4528..ff6e2cf94d 100644 --- a/core/fpdfapi/parser/cpdf_simple_parser.cpp +++ b/core/fpdfapi/parser/cpdf_simple_parser.cpp @@ -8,7 +8,8 @@ #include "core/fpdfapi/parser/fpdf_parser_utility.h" -CPDF_SimpleParser::CPDF_SimpleParser(const ByteStringView& str) : data_(str) {} +CPDF_SimpleParser::CPDF_SimpleParser(pdfium::span<const uint8_t> input) + : data_(input) {} CPDF_SimpleParser::~CPDF_SimpleParser() = default; @@ -17,12 +18,12 @@ ByteStringView CPDF_SimpleParser::GetWord() { // Skip whitespace and comment lines. while (1) { - if (data_.GetLength() <= cur_pos_) + if (data_.size() <= cur_pos_) return ByteStringView(); ch = data_[cur_pos_++]; while (PDFCharIsWhitespace(ch)) { - if (data_.GetLength() <= cur_pos_) + if (data_.size() <= cur_pos_) return ByteStringView(); ch = data_[cur_pos_++]; } @@ -31,7 +32,7 @@ ByteStringView CPDF_SimpleParser::GetWord() { break; while (1) { - if (data_.GetLength() <= cur_pos_) + if (data_.size() <= cur_pos_) return ByteStringView(); ch = data_[cur_pos_++]; @@ -46,7 +47,7 @@ ByteStringView CPDF_SimpleParser::GetWord() { // Find names if (ch == '/') { while (1) { - if (data_.GetLength() <= cur_pos_) + if (data_.size() <= cur_pos_) break; ch = data_[cur_pos_++]; @@ -56,29 +57,29 @@ ByteStringView CPDF_SimpleParser::GetWord() { break; } } - return data_.Mid(start_pos, dwSize); + return data_.subspan(start_pos, dwSize); } dwSize = 1; if (ch == '<') { - if (data_.GetLength() <= cur_pos_) - return data_.Mid(start_pos, dwSize); + if (data_.size() <= cur_pos_) + return data_.subspan(start_pos, dwSize); ch = data_[cur_pos_++]; if (ch == '<') { dwSize = 2; } else { - while (cur_pos_ < data_.GetLength() && data_[cur_pos_] != '>') + while (cur_pos_ < data_.size() && data_[cur_pos_] != '>') cur_pos_++; - if (cur_pos_ < data_.GetLength()) + if (cur_pos_ < data_.size()) cur_pos_++; dwSize = cur_pos_ - start_pos; } } else if (ch == '>') { - if (data_.GetLength() <= cur_pos_) - return data_.Mid(start_pos, dwSize); + if (data_.size() <= cur_pos_) + return data_.subspan(start_pos, dwSize); ch = data_[cur_pos_++]; if (ch == '>') @@ -87,7 +88,7 @@ ByteStringView CPDF_SimpleParser::GetWord() { cur_pos_--; } else if (ch == '(') { int level = 1; - while (cur_pos_ < data_.GetLength()) { + while (cur_pos_ < data_.size()) { if (data_[cur_pos_] == ')') { level--; if (level == 0) @@ -95,28 +96,28 @@ ByteStringView CPDF_SimpleParser::GetWord() { } if (data_[cur_pos_] == '\\') { - if (data_.GetLength() <= cur_pos_) + if (data_.size() <= cur_pos_) break; cur_pos_++; } else if (data_[cur_pos_] == '(') { level++; } - if (data_.GetLength() <= cur_pos_) + if (data_.size() <= cur_pos_) break; cur_pos_++; } - if (cur_pos_ < data_.GetLength()) + if (cur_pos_ < data_.size()) cur_pos_++; dwSize = cur_pos_ - start_pos; } - return data_.Mid(start_pos, dwSize); + return data_.subspan(start_pos, dwSize); } dwSize = 1; - while (cur_pos_ < data_.GetLength()) { + while (cur_pos_ < data_.size()) { ch = data_[cur_pos_++]; if (PDFCharIsDelimiter(ch) || PDFCharIsWhitespace(ch)) { @@ -125,5 +126,5 @@ ByteStringView CPDF_SimpleParser::GetWord() { } dwSize++; } - return data_.Mid(start_pos, dwSize); + return data_.subspan(start_pos, dwSize); } |