[gs-commits] mupdf 1.16.1.67 Fix unitest.epub regression.

[email protected] (Robin Watts) Thu, 3 Oct 2019 15:19:02 +0000 (UTC)
Newsgroups gmane.comp.printing.ghostscript.cvs
Message-ID <[email protected]>
commit 70ba1164ff892e9c4f8ad8dd8b86654d440977a4
Author: Robin Watts <[email protected]>
Date:   Mon Sep 30 17:41:08 2019 +0100

    Fix unitest.epub regression.
    
    It appears that we can try to access padding/margin/border for
    an inline block. Fix the code to cope with this, and add some
    asserts to check we never try to write to an inappropriate
    block.

diff --git a/source/html/html-imp.h b/source/html/html-imp.h
index 6b347a6..bd2f60f 100644
--- a/source/html/html-imp.h
+++ b/source/html/html-imp.h
@@ -218,12 +218,18 @@ struct fz_html_box_s
 	fz_html_flow *flow_head, **flow_tail;
 	char *id, *href;
 	fz_css_style style;
-	/* Only BOX_BLOCK and BOX_TABLE actually use the following */
+	/* Only BOX_{BLOCK,TABLE,TABLE_ROW,TABLE_CELL} actually use the following */
 	float padding[4];
 	float margin[4];
 	float border[4];
 };
 
+static inline int
+fz_html_box_has_boxes(fz_html_box *box)
+{
+	return (box->type == BOX_BLOCK || box->type == BOX_TABLE || box->type == BOX_TABLE_ROW || box->type == BOX_TABLE_CELL);
+}
+
 enum
 {
 	FLOW_WORD = 0,
diff --git a/source/html/html-layout.c b/source/html/html-layout.c
index f1e2b4e..a74cdc6 100644
--- a/source/html/html-layout.c
+++ b/source/html/html-layout.c
@@ -7,6 +7,7 @@
 #include <ft2build.h>
 
 #include <math.h>
+#include <assert.h>
 
 #undef DEBUG_HARFBUZZ
 
@@ -419,11 +420,13 @@ static void find_accumulated_margins(fz_context *ctx, fz_html_box *box, float *w
 {
 	while (box)
 	{
-		/* TODO: take into account collapsed margins */
-		*h += box->margin[T] + box->padding[T] + box->border[T];
-		*h += box->margin[B] + box->padding[B] + box->border[B];
-		*w += box->margin[L] + box->padding[L] + box->border[L];
-		*w += box->margin[R] + box->padding[R] + box->border[R];
+		if (fz_html_box_has_boxes(box)) {
+			/* TODO: take into account collapsed margins */
+			*h += box->margin[T] + box->padding[T] + box->border[T];
+			*h += box->margin[B] + box->padding[B] + box->border[B];
+			*w += box->margin[L] + box->padding[L] + box->border[L];
+			*w += box->margin[R] + box->padding[R] + box->border[R];
+		}
 		box = box->up;
 	}
 }
@@ -687,6 +690,7 @@ static float layout_block(fz_context *ctx, fz_html_box *box, float em, float top
 	float *border = box->border;
 	float *padding = box->padding;
 
+	assert(fz_html_box_has_boxes(box));
 	em = box->em = fz_from_css_number(style->font_size, em, em, em);
 
 	margin[0] = fz_from_css_number(style->margin[0], em, top_w, 0);
@@ -730,6 +734,7 @@ static float layout_block(fz_context *ctx, fz_html_box *box, float em, float top
 	{
 		if (child->type == BOX_BLOCK)
 		{
+			assert(fz_html_box_has_boxes(child));
 			vertical = layout_block(ctx, child, em, box->x, &box->b, box->w, page_h, vertical, hb_buf);
 			if (first)
 			{
@@ -743,6 +748,7 @@ static float layout_block(fz_context *ctx, fz_html_box *box, float em, float top
 		}
 		else if (child->type == BOX_TABLE)
 		{
+			assert(fz_html_box_has_boxes(child));
 			layout_table(ctx, child, box, page_h, hb_buf);
 			first = 0;
 			box->b = child->b + child->padding[B] + child->border[B] + child->margin[B];
@@ -1219,6 +1225,7 @@ static void draw_block_box(fz_context *ctx, fz_html_box *box, float page_top, fl
 	float *border = box->border;
 	float *padding = box->padding;
 
+	assert(fz_html_box_has_boxes(box));
 	x0 = box->x - padding[L];
 	y0 = box->y - padding[T];
 	x1 = box->x + box->w + padding[R];

http://git.ghostscript.com/?p=mupdf.git;a=commit;h=70ba1164ff892e9c4f8ad8dd8b86654d440977a4

--
MuPDF library
Artifex Software, Inc.