Change CFX_BmpDecompressor::ReadHeader() to return bool.
ReadHeader() currently returns either 1 or 2. Map these to true and
false, respectively, and have the one and only caller handle it
appropriately.
Change-Id: I7b793ae07034d85a3bf9a14d272b68d11e82ff21
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/56070
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcodec/bmp/cfx_bmpdecompressor.cpp b/core/fxcodec/bmp/cfx_bmpdecompressor.cpp
index e727147..4bba1b4 100644
--- a/core/fxcodec/bmp/cfx_bmpdecompressor.cpp
+++ b/core/fxcodec/bmp/cfx_bmpdecompressor.cpp
@@ -71,12 +71,12 @@
return context_->m_pDelegate->BmpInputImagePositionBuf(rcd_pos);
}
-int32_t CFX_BmpDecompressor::ReadHeader() {
+bool CFX_BmpDecompressor::ReadHeader() {
if (decode_status_ == DecodeStatus::kHeader) {
BmpFileHeader bmp_header;
if (!ReadData(reinterpret_cast<uint8_t*>(&bmp_header),
sizeof(BmpFileHeader))) {
- return 2;
+ return false;
}
bmp_header.bfType =
@@ -92,7 +92,7 @@
if (!ReadData(reinterpret_cast<uint8_t*>(&img_ifh_size_),
sizeof(img_ifh_size_))) {
- return 2;
+ return false;
}
img_ifh_size_ =
@@ -104,7 +104,7 @@
BmpCoreHeader bmp_core_header;
if (!ReadData(reinterpret_cast<uint8_t*>(&bmp_core_header),
sizeof(BmpCoreHeader))) {
- return 2;
+ return false;
}
width_ = FXWORD_GET_LSBFIRST(
@@ -121,7 +121,7 @@
BmpInfoHeader bmp_info_header;
if (!ReadData(reinterpret_cast<uint8_t*>(&bmp_info_header),
sizeof(BmpInfoHeader))) {
- return 2;
+ return false;
}
width_ = FXDWORD_GET_LSBFIRST(
@@ -151,7 +151,7 @@
BmpInfoHeader bmp_info_header;
if (!ReadData(reinterpret_cast<uint8_t*>(&bmp_info_header),
sizeof(bmp_info_header))) {
- return 2;
+ return false;
}
new_pos += img_ifh_size_;
@@ -161,7 +161,7 @@
}
if (!input_buffer_->Seek(new_pos.ValueOrDie()))
- return 2;
+ return false;
uint16_t bi_planes;
width_ = FXDWORD_GET_LSBFIRST(
@@ -259,7 +259,7 @@
SaveDecodingStatus(DecodeStatus::kPal);
}
if (decode_status_ != DecodeStatus::kPal)
- return 1;
+ return true;
if (compress_flag_ == kBmpBitfields) {
if (bit_counts_ != 16 && bit_counts_ != 32) {
@@ -269,7 +269,7 @@
uint32_t masks[3];
if (!ReadData(reinterpret_cast<uint8_t*>(masks), sizeof(masks)))
- return 2;
+ return false;
mask_red_ = FXDWORD_GET_LSBFIRST(reinterpret_cast<uint8_t*>(&masks[0]));
mask_green_ = FXDWORD_GET_LSBFIRST(reinterpret_cast<uint8_t*>(&masks[1]));
@@ -281,7 +281,7 @@
}
header_offset_ = std::max(header_offset_, 26 + img_ifh_size_);
SaveDecodingStatus(DecodeStatus::kDataPre);
- return 1;
+ return true;
}
if (bit_counts_ == 16) {
@@ -298,7 +298,7 @@
std::vector<uint8_t> src_pal(src_pal_size);
uint8_t* src_pal_data = src_pal.data();
if (!ReadData(src_pal_data, src_pal_size)) {
- return 2;
+ return false;
}
palette_.resize(pal_num_);
@@ -320,7 +320,7 @@
header_offset_ = std::max(
header_offset_, 14 + img_ifh_size_ + pal_num_ * (pal_type_ ? 3 : 4));
SaveDecodingStatus(DecodeStatus::kDataPre);
- return 1;
+ return true;
}
bool CFX_BmpDecompressor::ValidateFlag() const {
diff --git a/core/fxcodec/bmp/cfx_bmpdecompressor.h b/core/fxcodec/bmp/cfx_bmpdecompressor.h
index 5144b98..223ab63 100644
--- a/core/fxcodec/bmp/cfx_bmpdecompressor.h
+++ b/core/fxcodec/bmp/cfx_bmpdecompressor.h
@@ -25,7 +25,7 @@
void Error();
int32_t DecodeImage();
- int32_t ReadHeader();
+ bool ReadHeader();
void SetInputBuffer(RetainPtr<CFX_CodecMemory> codec_memory);
FX_FILESIZE GetAvailInput() const;
diff --git a/core/fxcodec/codec/bmpmodule.cpp b/core/fxcodec/codec/bmpmodule.cpp
index 3ad8f0f..26d1bfd 100644
--- a/core/fxcodec/codec/bmpmodule.cpp
+++ b/core/fxcodec/codec/bmpmodule.cpp
@@ -40,9 +40,8 @@
if (setjmp(*ctx->m_Bmp.jmpbuf()))
return 0;
- int32_t ret = ctx->m_Bmp.ReadHeader();
- if (ret != 1)
- return ret;
+ if (!ctx->m_Bmp.ReadHeader())
+ return 2;
*width = ctx->m_Bmp.width();
*height = ctx->m_Bmp.height();