0

PDF: Handle FPDFPage_GetRotation() error in PDFiumPage::GetBoundingBox()

If FPDFPage_GetRotation() returns -1, do not cast that to enum class
Rotation, which does not have a corresponding enum value.

Bug: 388557904
Change-Id: Id6e3c788a67b6ce4c36e09b38bdb913ad548dd13
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6168649
Commit-Queue: Lei Zhang <thestig@chromium.org>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Reviewed-by: Andy Phan <andyphan@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1405103}
This commit is contained in:
Lei Zhang
2025-01-10 17:06:26 -08:00
committed by Chromium LUCI CQ
parent 30654cd95d
commit ba6a7c96e3

@ -79,6 +79,21 @@ enum class Rotation {
kRotate270 = 3,
};
std::optional<Rotation> GetRotationFromRawValue(int rotation) {
switch (rotation) {
case 0:
return Rotation::kRotate0;
case 1:
return Rotation::kRotate90;
case 2:
return Rotation::kRotate180;
case 3:
return Rotation::kRotate270;
default:
return std::nullopt;
}
}
gfx::RectF FloatPageRectToPixelRect(FPDF_PAGE page, const gfx::RectF& input) {
int output_width = FPDF_GetPageWidthF(page);
int output_height = FPDF_GetPageHeightF(page);
@ -746,9 +761,14 @@ gfx::RectF PDFiumPage::GetBoundingBox() {
return gfx::RectF();
}
std::optional<Rotation> rotation =
GetRotationFromRawValue(FPDFPage_GetRotation(page));
if (!rotation.has_value()) {
return gfx::RectF();
}
// Page width and height are already swapped based on page rotation.
gfx::SizeF page_size(FPDF_GetPageWidthF(page), FPDF_GetPageHeightF(page));
Rotation rotation = static_cast<Rotation>(FPDFPage_GetRotation(page));
// Start with bounds with the left and bottom values at the max possible
// bounds and the right and top values at the min possible bounds. Bounds are
@ -779,10 +799,10 @@ gfx::RectF PDFiumPage::GetBoundingBox() {
}
gfx::RectF bounding_box =
GetRotatedRectF(rotation, page_size, largest_bounds);
GetRotatedRectF(rotation.value(), page_size, largest_bounds);
gfx::RectF effective_crop_box =
GetEffectiveCropBox(page, rotation, page_size);
GetEffectiveCropBox(page, rotation.value(), page_size);
// If the bounding box is empty, default to the effective crop box.
if (bounding_box.IsEmpty()) {