[pango/tab-assert-fix] layout: Handle a corner case




commit 3bb2249f3452061247655a11696a93dc5eeae584
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Dec 9 14:26:25 2021 -0500

    layout: Handle a corner case
    
    We can't break in a tab run.
    This fixes an assertion found by afl.
    
    Testcase included.
    
    Fixes: #638

 pango/pango-layout.c            |   4 +-
 tests/layouts/tab-assert.layout | 183 ++++++++++++++++++++++++++++++++++++++++
 tests/meson.build               |   1 +
 3 files changed, 187 insertions(+), 1 deletion(-)
---
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index a495596c..a3f8b552 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -4496,12 +4496,14 @@ process_line (PangoLayout    *layout,
       switch (result)
         {
         case BREAK_ALL_FIT:
-          if (can_break_in (layout, state->start_offset, old_num_chars, first_item_in_line))
+          if (layout->text[item->offset] != '\t' &&
+              can_break_in (layout, state->start_offset, old_num_chars, first_item_in_line))
             {
               have_break = TRUE;
               break_remaining_width = old_remaining_width;
               break_start_offset = state->start_offset;
               break_link = line->runs->next;
+              DEBUG1 ("all-fit, have break");
             }
 
           state->items = g_list_delete_link (state->items, state->items);
diff --git a/tests/layouts/tab-assert.layout b/tests/layouts/tab-assert.layout
new file mode 100644
index 00000000..0e3ebf25
--- /dev/null
+++ b/tests/layouts/tab-assert.layout
@@ -0,0 +1,183 @@
+{
+  "context" : {
+    "font" : "serif 12",
+    "base-gravity" : "south",
+    "gravity-hint" : "natural",
+    "base-dir" : "weak-ltr",
+    "round-glyph-positions" : true,
+    "transform" : [
+      1,
+      0,
+      0,
+      1,
+      0,
+      0
+    ]
+  },
+  "comment" : "This layout was triggering an assertion in process_line",
+  "text" : " \t  ",
+  "width" : 0,
+  "output" : {
+    "is-wrapped" : false,
+    "is-ellipsized" : false,
+    "unknown-glyphs" : 0,
+    "width" : 56320,
+    "height" : 56320,
+    "log-attrs" : [
+      {
+        "char-break" : true,
+        "white" : true,
+        "cursor-position" : true,
+        "sentence-boundary" : true,
+        "backspace-deletes-character" : true,
+        "expandable-space" : true,
+        "word-boundary" : true
+      },
+      {
+        "line-break" : true,
+        "char-break" : true,
+        "white" : true,
+        "cursor-position" : true,
+        "word-boundary" : true
+      },
+      {
+        "char-break" : true,
+        "white" : true,
+        "cursor-position" : true,
+        "backspace-deletes-character" : true,
+        "expandable-space" : true,
+        "word-boundary" : true
+      },
+      {
+        "char-break" : true,
+        "white" : true,
+        "cursor-position" : true,
+        "expandable-space" : true
+      },
+      {
+        "line-break" : true,
+        "mandatory-break" : true,
+        "char-break" : true,
+        "white" : true,
+        "cursor-position" : true,
+        "sentence-boundary" : true,
+        "word-boundary" : true
+      }
+    ],
+    "lines" : [
+      {
+        "start-index" : 0,
+        "length" : 4,
+        "paragraph-start" : true,
+        "direction" : "ltr",
+        "runs" : [
+          {
+            "offset" : 0,
+            "length" : 1,
+            "text" : " ",
+            "bidi-level" : 0,
+            "gravity" : "south",
+            "language" : "en-us",
+            "script" : "common",
+            "font" : {
+              "description" : "DejaVu Sans 12",
+              "checksum" : "69ccd07023a72ceb27a5e5c22f728627353b60a198170f5e58dd7014221abf01",
+              "matrix" : [
+                1,
+                -0,
+                -0,
+                1,
+                0,
+                0
+              ]
+            },
+            "flags" : 0,
+            "y-offset" : 0,
+            "start-x-offset" : 0,
+            "end-x-offset" : 0,
+            "glyphs" : [
+              {
+                "glyph" : 3,
+                "width" : 5120,
+                "is-cluster-start" : true,
+                "log-cluster" : 0
+              }
+            ]
+          },
+          {
+            "offset" : 1,
+            "length" : 1,
+            "text" : "\t",
+            "bidi-level" : 0,
+            "gravity" : "south",
+            "language" : "en-us",
+            "script" : "common",
+            "font" : {
+              "description" : "DejaVu Sans 12",
+              "checksum" : "69ccd07023a72ceb27a5e5c22f728627353b60a198170f5e58dd7014221abf01",
+              "matrix" : [
+                1,
+                -0,
+                -0,
+                1,
+                0,
+                0
+              ]
+            },
+            "flags" : 0,
+            "y-offset" : 0,
+            "start-x-offset" : 0,
+            "end-x-offset" : 0,
+            "glyphs" : [
+              {
+                "glyph" : 268435455,
+                "width" : 40960,
+                "is-cluster-start" : true,
+                "log-cluster" : 0
+              }
+            ]
+          },
+          {
+            "offset" : 2,
+            "length" : 2,
+            "text" : "  ",
+            "bidi-level" : 0,
+            "gravity" : "south",
+            "language" : "en-us",
+            "script" : "common",
+            "font" : {
+              "description" : "DejaVu Sans 12",
+              "checksum" : "69ccd07023a72ceb27a5e5c22f728627353b60a198170f5e58dd7014221abf01",
+              "matrix" : [
+                1,
+                -0,
+                -0,
+                1,
+                0,
+                0
+              ]
+            },
+            "flags" : 0,
+            "y-offset" : 0,
+            "start-x-offset" : 0,
+            "end-x-offset" : 0,
+            "glyphs" : [
+              {
+                "glyph" : 3,
+                "width" : 5120,
+                "is-cluster-start" : true,
+                "log-cluster" : 0
+              },
+              {
+                "glyph" : 3,
+                "width" : 5120,
+                "is-cluster-start" : true,
+                "log-cluster" : 1
+              }
+            ]
+          }
+        ]
+      }
+    ]
+  }
+}
diff --git a/tests/meson.build b/tests/meson.build
index b15c7291..54592668 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -120,6 +120,7 @@ installed_test_layouts_data = [
   'layouts/valid-21.layout',
   'layouts/valid-22.layout',
   'layouts/tab-crash.layout',
+  'layouts/tab-assert.layout',
 ]
 
 test_markups_data = [


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]