Commit f4f08cea authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Improve PDF RecursiveGetStructTree() function.

Check for FPDF_StructElement_CountChildren() result for negative values,
which means error. Do not continue on error. Also check the children
count earlier in the function, and return early when possible.

Change-Id: If7365ef32054bc9d6200482c458cfc2471af8bc0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2337127
Commit-Queue: Dominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794727}
parent 3c5180c2
......@@ -133,6 +133,10 @@ bool IsValidPrintableArea(const gfx::Size& page_size,
}
base::Value RecursiveGetStructTree(FPDF_STRUCTELEMENT struct_elem) {
int children_count = FPDF_StructElement_CountChildren(struct_elem);
if (children_count <= 0)
return base::Value(base::Value::Type::NONE);
base::Optional<base::string16> opt_type =
CallPDFiumWideStringBufferApiAndReturnOptional(
base::BindRepeating(FPDF_StructElement_GetType, struct_elem), true);
......@@ -155,10 +159,6 @@ base::Value RecursiveGetStructTree(FPDF_STRUCTELEMENT struct_elem) {
if (opt_lang)
result.SetStringKey("lang", *opt_lang);
int children_count = FPDF_StructElement_CountChildren(struct_elem);
if (children_count == 0)
return base::Value(base::Value::Type::NONE);
base::Value children(base::Value::Type::LIST);
for (int i = 0; i < children_count; i++) {
FPDF_STRUCTELEMENT child_elem =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment