Skip to content
Permalink
Browse files Browse the repository at this point in the history
Fix a crash bug with bogus table attributes (Issue #417)
  • Loading branch information
michaelrsweet committed Apr 1, 2021
1 parent 6a8322a commit 0ddab26
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
@@ -1,6 +1,7 @@
# Changes in HTMLDOC v1.9.12

- Fixed a crash bug with "data:" URIs and EPUB output (Issue #410)
- Fixed a crach bug with bogus table attributes (Issue #417)
- Fixed a crash bug with malformed URIs (Issue #418)
- Fixed a crash bug with malformed GIF files (Issue #423)
- Fixed some issues reported by Coverity.
Expand Down
23 changes: 19 additions & 4 deletions htmldoc/ps-pdf.cxx
Expand Up @@ -6379,6 +6379,9 @@ parse_table(tree_t *t, // I - Tree to parse
table_width = (float)(atof((char *)var) * (right - left) / 100.0f);
else
table_width = (float)(atoi((char *)var) * PagePrintWidth / _htmlBrowserWidth);

if (table_width < 0.0f || table_width > PagePrintWidth)
table_width = right - left;
}
else
table_width = right - left;
Expand All @@ -6396,19 +6399,31 @@ parse_table(tree_t *t, // I - Tree to parse
DEBUG_printf(("table_width = %.1f\n", table_width));

if ((var = htmlGetVariable(t, (uchar *)"CELLPADDING")) != NULL)
table.cellpadding = atoi((char *)var);
{
if ((table.cellpadding = atoi((char *)var)) < 0.0f)
table.cellpadding = 0.0f;
else if (table.cellpadding > 20.0f)
table.cellpadding = 20.0f;
}
else
table.cellpadding = 1.0f;

if ((var = htmlGetVariable(t, (uchar *)"CELLSPACING")) != NULL)
cellspacing = atoi((char *)var);
{
if ((cellspacing = atoi((char *)var)) < 0.0f)
cellspacing = 0.0f;
else if (cellspacing > 20.0f)
cellspacing = 20.0f;
}
else
cellspacing = 0.0f;

if ((var = htmlGetVariable(t, (uchar *)"BORDER")) != NULL)
{
if ((table.border = (float)atof((char *)var)) == 0.0 && var[0] != '0')
if ((table.border = (float)atof((char *)var)) <= 0.0 && var[0] != '0')
table.border = 1.0f;
else if (table.border > 20.0f)
table.border = 20.0f;

table.cellpadding += table.border;
}
Expand Down Expand Up @@ -6438,7 +6453,7 @@ parse_table(tree_t *t, // I - Tree to parse

table.border_size = table.border - 1.0f;

cellspacing *= PagePrintWidth / _htmlBrowserWidth;
cellspacing *= PagePrintWidth / _htmlBrowserWidth;
table.cellpadding *= PagePrintWidth / _htmlBrowserWidth;
table.border *= PagePrintWidth / _htmlBrowserWidth;
table.border_size *= PagePrintWidth / _htmlBrowserWidth;
Expand Down

0 comments on commit 0ddab26

Please sign in to comment.