Early return for zero dest_len in WeightTable::CalculateWeights().
Avoid a possible floating div-by-zero later on and return a nice empty
table for this case.
Change-Id: Ib8bdc732f778e1368a32cb0e60545b443d3df1c6
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/82171
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxge/dib/cstretchengine.cpp b/core/fxge/dib/cstretchengine.cpp
index 5b2ff3b..ade1c81 100644
--- a/core/fxge/dib/cstretchengine.cpp
+++ b/core/fxge/dib/cstretchengine.cpp
@@ -67,6 +67,9 @@
m_ItemSizeBytes = 0;
m_WeightTablesSizeBytes = 0;
m_WeightTables.clear();
+ if (dest_len == 0)
+ return true;
+
if (dest_min > dest_max)
return false;
diff --git a/core/fxge/dib/cstretchengine_unittest.cpp b/core/fxge/dib/cstretchengine_unittest.cpp
index 6db7667..2053155 100644
--- a/core/fxge/dib/cstretchengine_unittest.cpp
+++ b/core/fxge/dib/cstretchengine_unittest.cpp
@@ -135,3 +135,9 @@
CStretchEngine::WeightTable table;
ASSERT_TRUE(table.CalculateWeights(100, 0, 100, 0, 0, 0, options));
}
+
+TEST(CStretchEngine, ZeroLengthDest) {
+ FXDIB_ResampleOptions options;
+ CStretchEngine::WeightTable table;
+ ASSERT_TRUE(table.CalculateWeights(0, 0, 0, 100, 0, 100, options));
+}