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

Unified Diff: core/fxcrt/fx_basic_buffer.cpp

Issue 2268693003: Fix more integer overflows inside ReadPageHintTable(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Simplify CFX_BitStream::ByteAlign Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fxcrt/fx_basic_buffer.cpp
diff --git a/core/fxcrt/fx_basic_buffer.cpp b/core/fxcrt/fx_basic_buffer.cpp
index 91ca6dad7c3572629b6a5f54924e64305c1c6133..5ee1a659e508bb6fb4b9e998c3222a0cd9ba1cf0 100644
--- a/core/fxcrt/fx_basic_buffer.cpp
+++ b/core/fxcrt/fx_basic_buffer.cpp
@@ -187,24 +187,24 @@ void CFX_BitStream::Init(const uint8_t* pData, uint32_t dwSize) {
m_BitSize = dwSize * 8;
m_BitPos = 0;
}
+
void CFX_BitStream::ByteAlign() {
- int mod = m_BitPos % 8;
- if (mod == 0) {
- return;
- }
- m_BitPos += 8 - mod;
+ m_BitPos = (m_BitPos + 7) & ~7;
}
+
uint32_t CFX_BitStream::GetBits(uint32_t nBits) {
- if (nBits > m_BitSize || m_BitPos + nBits > m_BitSize) {
+ if (nBits > m_BitSize || m_BitPos + nBits > m_BitSize)
return 0;
- }
+
if (nBits == 1) {
int bit = (m_pData[m_BitPos / 8] & (1 << (7 - m_BitPos % 8))) ? 1 : 0;
m_BitPos++;
return bit;
}
+
uint32_t byte_pos = m_BitPos / 8;
- uint32_t bit_pos = m_BitPos % 8, bit_left = nBits;
+ uint32_t bit_pos = m_BitPos % 8;
+ uint32_t bit_left = nBits;
uint32_t result = 0;
if (bit_pos) {
if (8 - bit_pos >= bit_left) {
@@ -220,9 +220,8 @@ uint32_t CFX_BitStream::GetBits(uint32_t nBits) {
bit_left -= 8;
result |= m_pData[byte_pos++] << bit_left;
}
- if (bit_left) {
+ if (bit_left)
result |= m_pData[byte_pos] >> (8 - bit_left);
- }
m_BitPos += nBits;
return result;
}
@@ -249,12 +248,12 @@ bool CFX_FileBufferArchive::Flush() {
}
int32_t CFX_FileBufferArchive::AppendBlock(const void* pBuf, size_t size) {
- if (!pBuf || size < 1) {
+ if (!pBuf || size < 1)
return 0;
- }
- if (!m_pBuffer) {
+
+ if (!m_pBuffer)
m_pBuffer.reset(FX_Alloc(uint8_t, kBufSize));
- }
+
const uint8_t* buffer = reinterpret_cast<const uint8_t*>(pBuf);
size_t temp_size = size;
while (temp_size) {
« no previous file with comments | « core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698