Improve fxbarcode matrix classes.
CBC_CommonByteMatrix limits its memory allocation, so the memory size
calculation cannot overflow. Simplify the Vector2D usage to a resize()
call. Also remove the Fill() call and combine that into the resize().
CBC_CommonBitMatrix similarly cannot overflow its memory calculation, so
switch away from Vector2D there as well. Also switch CBC_CommonBitMatrix
to using DataVector, and make its memory limit check more consistent
with the actual allocation size.
Change-Id: I28f9608ac36b41aba5af50f1b49ab6ac1bf61f51
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/97890
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fxbarcode/common/BC_CommonBitMatrix.cpp b/fxbarcode/common/BC_CommonBitMatrix.cpp
index e193847..7b94aa3 100644
--- a/fxbarcode/common/BC_CommonBitMatrix.cpp
+++ b/fxbarcode/common/BC_CommonBitMatrix.cpp
@@ -22,15 +22,14 @@
#include "fxbarcode/common/BC_CommonBitMatrix.h"
-#include "core/fxcrt/stl_util.h"
+#include "core/fxcrt/data_vector.h"
#include "third_party/base/check_op.h"
CBC_CommonBitMatrix::CBC_CommonBitMatrix(size_t width, size_t height)
: m_height(height), m_rowSize((width + 31) >> 5) {
static constexpr int32_t kMaxBits = 1024 * 1024 * 1024; // 1 Gb.
- CHECK_LT(width, kMaxBits / height);
-
- m_bits = fxcrt::Vector2D<uint32_t>(m_rowSize, m_height);
+ CHECK_LT(m_rowSize, kMaxBits / m_height);
+ m_bits.resize(m_rowSize * m_height);
}
CBC_CommonBitMatrix::~CBC_CommonBitMatrix() = default;
diff --git a/fxbarcode/common/BC_CommonBitMatrix.h b/fxbarcode/common/BC_CommonBitMatrix.h
index 4e9bf1e..1922935 100644
--- a/fxbarcode/common/BC_CommonBitMatrix.h
+++ b/fxbarcode/common/BC_CommonBitMatrix.h
@@ -10,7 +10,7 @@
#include <stddef.h>
#include <stdint.h>
-#include <vector>
+#include "core/fxcrt/data_vector.h"
class CBC_CommonBitMatrix {
public:
@@ -23,7 +23,7 @@
private:
const size_t m_height;
const size_t m_rowSize;
- std::vector<uint32_t> m_bits;
+ DataVector<uint32_t> m_bits;
};
#endif // FXBARCODE_COMMON_BC_COMMONBITMATRIX_H_
diff --git a/fxbarcode/common/BC_CommonByteMatrix.cpp b/fxbarcode/common/BC_CommonByteMatrix.cpp
index baba324..e7849e2 100644
--- a/fxbarcode/common/BC_CommonByteMatrix.cpp
+++ b/fxbarcode/common/BC_CommonByteMatrix.cpp
@@ -23,15 +23,16 @@
#include <algorithm>
#include <iterator>
-#include "core/fxcrt/stl_util.h"
+
+#include "core/fxcrt/data_vector.h"
#include "third_party/base/check_op.h"
CBC_CommonByteMatrix::CBC_CommonByteMatrix(size_t width, size_t height)
: m_width(width), m_height(height) {
static constexpr size_t kMaxBytes = 256 * 1024 * 1024; // 256 MB.
- CHECK_LT(width, kMaxBytes / height);
- m_bytes = fxcrt::Vector2D<uint8_t, FxAllocAllocator<uint8_t>>(height, width);
- Fill(0xff);
+ static constexpr uint8_t kDefaultFill = 0xff;
+ CHECK_LT(m_width, kMaxBytes / m_height);
+ m_bytes.resize(m_width * m_height, kDefaultFill);
}
CBC_CommonByteMatrix::~CBC_CommonByteMatrix() = default;