summaryrefslogtreecommitdiff
path: root/core/fpdfapi/page
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/page')
-rw-r--r--core/fpdfapi/page/cpdf_streamparser.cpp60
1 files changed, 29 insertions, 31 deletions
diff --git a/core/fpdfapi/page/cpdf_streamparser.cpp b/core/fpdfapi/page/cpdf_streamparser.cpp
index e8116cf980..c3dc54a734 100644
--- a/core/fpdfapi/page/cpdf_streamparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamparser.cpp
@@ -8,7 +8,9 @@
#include <limits.h>
+#include <algorithm>
#include <memory>
+#include <sstream>
#include <utility>
#include "core/fpdfapi/cpdf_modulemgr.h"
@@ -220,7 +222,7 @@ std::unique_ptr<CPDF_Stream> CPDF_StreamParser::ReadInlineStream(
memcpy(pData.get(), m_pBuf + m_Pos, dwStreamSize);
m_Pos += dwStreamSize;
}
- pDict->SetNewFor<CPDF_Number>("Length", (int)dwStreamSize);
+ pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(dwStreamSize));
return pdfium::MakeUnique<CPDF_Stream>(std::move(pData), dwStreamSize,
std::move(pDict));
}
@@ -473,7 +475,7 @@ CFX_ByteString CPDF_StreamParser::ReadString() {
return CFX_ByteString();
uint8_t ch = m_pBuf[m_Pos++];
- CFX_ByteTextBuf buf;
+ std::ostringstream buf;
int parlevel = 0;
int status = 0;
int iEscCode = 0;
@@ -482,20 +484,19 @@ CFX_ByteString CPDF_StreamParser::ReadString() {
case 0:
if (ch == ')') {
if (parlevel == 0) {
- if (buf.GetLength() > kMaxStringLength) {
- return CFX_ByteString(buf.GetBuffer(), kMaxStringLength);
- }
- return buf.MakeString();
+ return CFX_ByteString(
+ buf.str().c_str(),
+ std::min(static_cast<int>(buf.tellp()), kMaxStringLength));
}
parlevel--;
- buf.AppendChar(')');
+ buf << ')';
} else if (ch == '(') {
parlevel++;
- buf.AppendChar('(');
+ buf << '(';
} else if (ch == '\\') {
status = 1;
} else {
- buf.AppendChar((char)ch);
+ buf << static_cast<char>(ch);
}
break;
case 1:
@@ -505,21 +506,21 @@ CFX_ByteString CPDF_StreamParser::ReadString() {
break;
}
if (ch == 'n') {
- buf.AppendChar('\n');
+ buf << '\n';
} else if (ch == 'r') {
- buf.AppendChar('\r');
+ buf << '\r';
} else if (ch == 't') {
- buf.AppendChar('\t');
+ buf << '\t';
} else if (ch == 'b') {
- buf.AppendChar('\b');
+ buf << '\b';
} else if (ch == 'f') {
- buf.AppendChar('\f');
+ buf << '\f';
} else if (ch == '\r') {
status = 4;
break;
} else if (ch == '\n') {
} else {
- buf.AppendChar(ch);
+ buf << static_cast<char>(ch);
}
status = 0;
break;
@@ -529,7 +530,7 @@ CFX_ByteString CPDF_StreamParser::ReadString() {
iEscCode * 8 + FXSYS_DecimalCharToInt(static_cast<char>(ch));
status = 3;
} else {
- buf.AppendChar(iEscCode);
+ buf << static_cast<char>(iEscCode);
status = 0;
continue;
}
@@ -538,19 +539,18 @@ CFX_ByteString CPDF_StreamParser::ReadString() {
if (ch >= '0' && ch <= '7') {
iEscCode =
iEscCode * 8 + FXSYS_DecimalCharToInt(static_cast<char>(ch));
- buf.AppendChar(iEscCode);
+ buf << static_cast<char>(iEscCode);
status = 0;
} else {
- buf.AppendChar(iEscCode);
+ buf << static_cast<char>(iEscCode);
status = 0;
continue;
}
break;
case 4:
status = 0;
- if (ch != '\n') {
+ if (ch != '\n')
continue;
- }
break;
}
if (!PositionIsInBounds())
@@ -561,17 +561,16 @@ CFX_ByteString CPDF_StreamParser::ReadString() {
if (PositionIsInBounds())
++m_Pos;
- if (buf.GetLength() > kMaxStringLength) {
- return CFX_ByteString(buf.GetBuffer(), kMaxStringLength);
- }
- return buf.MakeString();
+ return CFX_ByteString(
+ buf.str().c_str(),
+ std::min(static_cast<int>(buf.tellp()), kMaxStringLength));
}
CFX_ByteString CPDF_StreamParser::ReadHexString() {
if (!PositionIsInBounds())
return CFX_ByteString();
- CFX_ByteTextBuf buf;
+ std::ostringstream buf;
bool bFirst = true;
int code = 0;
while (PositionIsInBounds()) {
@@ -588,17 +587,16 @@ CFX_ByteString CPDF_StreamParser::ReadHexString() {
code = val * 16;
} else {
code += val;
- buf.AppendByte((uint8_t)code);
+ buf << static_cast<uint8_t>(code);
}
bFirst = !bFirst;
}
if (!bFirst)
- buf.AppendChar((char)code);
-
- if (buf.GetLength() > kMaxStringLength)
- return CFX_ByteString(buf.GetBuffer(), kMaxStringLength);
+ buf << static_cast<char>(code);
- return buf.MakeString();
+ return CFX_ByteString(
+ buf.str().c_str(),
+ std::min(static_cast<int>(buf.tellp()), kMaxStringLength));
}
bool CPDF_StreamParser::PositionIsInBounds() const {