Changeset 76721 in webkit


Ignore:
Timestamp:
Jan 26, 2011 2:43:44 PM (13 years ago)
Author:
mario@webkit.org
Message:

2011-01-26 Mario Sanchez Prada <msanchez@igalia.com>

Reviewed by Martin Robinson.

[GTK] Reliable crash with getTextAtOffset()
https://bugs.webkit.org/show_bug.cgi?id=53131

Properly calculate length in bytes for a UTF8 substring.

  • accessibility/gtk/AccessibilityObjectWrapperAtk.cpp: (utf8Substr): Use character instead of bytes as units to calculate the length in bytes for the UTF8 string.

2011-01-26 Mario Sanchez Prada <msanchez@igalia.com>

Reviewed by Martin Robinson.

[GTK] Reliable crash with getTextAtOffset()
https://bugs.webkit.org/show_bug.cgi?id=53131

New unit test to check the fix for this bug.

  • tests/testatk.c: (testWebkitAtkGetTextAtOffsetWithSpecialCharacters): New. (main): Add new unit test.
Location:
trunk/Source
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r76719 r76721  
     12011-01-26  Mario Sanchez Prada  <msanchez@igalia.com>
     2
     3        Reviewed by Martin Robinson.
     4
     5        [GTK] Reliable crash with getTextAtOffset()
     6        https://bugs.webkit.org/show_bug.cgi?id=53131
     7
     8        Properly calculate length in bytes for a UTF8 substring.
     9
     10        * accessibility/gtk/AccessibilityObjectWrapperAtk.cpp:
     11        (utf8Substr): Use character instead of bytes as units to
     12        calculate the length in bytes for the UTF8 string.
     13
    1142011-01-25  Dimitri Glazkov  <dglazkov@chromium.org>
    215
  • trunk/Source/WebCore/accessibility/gtk/AccessibilityObjectWrapperAtk.cpp

    r76442 r76721  
    995995        return 0;
    996996    gchar* startPtr = g_utf8_offset_to_pointer(string, start);
    997     gsize lenInBytes = g_utf8_offset_to_pointer(string, end) -  startPtr + 1;
     997    gsize lenInBytes = g_utf8_offset_to_pointer(string, end + 1) -  startPtr;
    998998    gchar* output = static_cast<gchar*>(g_malloc0(lenInBytes + 1));
    999999    return g_utf8_strncpy(output, startPtr, end - start + 1);
  • trunk/Source/WebKit/gtk/ChangeLog

    r76351 r76721  
     12011-01-26  Mario Sanchez Prada  <msanchez@igalia.com>
     2
     3        Reviewed by Martin Robinson.
     4
     5        [GTK] Reliable crash with getTextAtOffset()
     6        https://bugs.webkit.org/show_bug.cgi?id=53131
     7
     8        New unit test to check the fix for this bug.
     9
     10        * tests/testatk.c:
     11        (testWebkitAtkGetTextAtOffsetWithSpecialCharacters): New.
     12        (main): Add new unit test.
     13
    1142011-01-21  Carlos Garcia Campos  <cgarcia@igalia.com>
    215
  • trunk/Source/WebKit/gtk/tests/testatk.c

    r75250 r76721  
    3333static const char* contentsWithNewlines = "<html><body><p>This is a test. \n\nThis\n is the second sentence. And this the third.</p></body></html>";
    3434
     35static const char* contentsWithSpecialChars = "<html><body><p>&laquo;&nbsp;This is a paragraph with &ldquo;special&rdquo; characters inside.&nbsp;&raquo;</p></body></html>";
     36
    3537static const char* contentsInTextarea = "<html><body><textarea cols='80'>This is a test. This is the second sentence. And this the third.</textarea></body></html>";
    3638
     
    450452
    451453    runGetTextTests(textObject);
     454
     455    g_object_unref(webView);
     456}
     457
     458static void testWebkitAtkGetTextAtOffsetWithSpecialCharacters()
     459{
     460    WebKitWebView* webView = WEBKIT_WEB_VIEW(webkit_web_view_new());
     461    g_object_ref_sink(webView);
     462    GtkAllocation allocation = { 0, 0, 800, 600 };
     463    gtk_widget_size_allocate(GTK_WIDGET(webView), &allocation);
     464    webkit_web_view_load_string(webView, contentsWithSpecialChars, 0, 0, 0);
     465
     466    /* Wait for the accessible objects to be created. */
     467    waitForAccessibleObjects();
     468
     469    /* Get to the inner AtkText object. */
     470    AtkObject* object = gtk_widget_get_accessible(GTK_WIDGET(webView));
     471    g_assert(object);
     472    object = atk_object_ref_accessible_child(object, 0);
     473    g_assert(object);
     474
     475    AtkText* textObject = ATK_TEXT(object);
     476    g_assert(ATK_IS_TEXT(textObject));
     477
     478    const gchar* expectedText = "\302\253\302\240This is a paragraph with \342\200\234special\342\200\235 characters inside.\302\240\302\273";
     479    char* text = atk_text_get_text(textObject, 0, -1);
     480    g_assert_cmpstr(text, ==, expectedText);
     481    g_free(text);
     482
     483    /* Check that getting the text with ATK_TEXT_BOUNDARY_LINE_START
     484       and ATK_TEXT_BOUNDARY_LINE_END does not crash because of not
     485       properly handling characters inside the UTF-8 string. */
     486    testGetTextFunction(textObject, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_START, 0, expectedText, 0, 57);
     487    testGetTextFunction(textObject, atk_text_get_text_at_offset, ATK_TEXT_BOUNDARY_LINE_END, 0, expectedText, 0, 57);
    452488
    453489    g_object_unref(webView);
     
    13211357    g_test_add_func("/webkit/atk/getTextAtOffsetTextarea", testWebkitAtkGetTextAtOffsetTextarea);
    13221358    g_test_add_func("/webkit/atk/getTextAtOffsetTextInput", testWebkitAtkGetTextAtOffsetTextInput);
     1359    g_test_add_func("/webkit/atk/getTextAtOffsetWithSpecialCharacters", testWebkitAtkGetTextAtOffsetWithSpecialCharacters);
    13231360    g_test_add_func("/webkit/atk/getTextInParagraphAndBodySimple", testWebkitAtkGetTextInParagraphAndBodySimple);
    13241361    g_test_add_func("/webkit/atk/getTextInParagraphAndBodyModerate", testWebkitAtkGetTextInParagraphAndBodyModerate);
Note: See TracChangeset for help on using the changeset viewer.