<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>128068</bug_id>
          
          <creation_ts>2014-02-02 00:28:42 -0800</creation_ts>
          <short_desc>graphics/StringTruncator.cpp:172: possible bad array index ?</short_desc>
          <delta_ts>2023-05-27 16:36:57 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Platform</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>INVALID</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="David Binderman">dcb314</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ahmad.saleem792</cc>
    
    <cc>ap</cc>
    
    <cc>dbates</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>974746</commentid>
    <comment_count>0</comment_count>
    <who name="David Binderman">dcb314</who>
    <bug_when>2014-02-02 00:28:42 -0800</bug_when>
    <thetext>I just ran the static analyser &quot;cppcheck&quot; over the source
code of webkitgtk-2.3.4

It said many things, including

[Source/WebCore/platform/graphics/StringTruncator.cpp:172]: (style) Array index &apos;adjustedStartIndex&apos; is used before limits check.

Source code is

    // Strip single character after ellipsis character, when that character is preceded by a space
    if (adjustedStartIndex &lt; length &amp;&amp; string[adjustedStartIndex] != space
        &amp;&amp; adjustedStartIndex &lt; length - 1 &amp;&amp; string[adjustedStartIndex + 1] == space)
        ++adjustedStartIndex;

Maybe

    if (adjustedStartIndex &lt; length &amp;&amp; string[adjustedStartIndex] != space
        &amp;&amp; adjustedStartIndex &gt; 0 &amp;&amp; string[adjustedStartIndex - 1] == space)

would be better code</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>982523</commentid>
    <comment_count>1</comment_count>
    <who name="Daniel Bates">dbates</who>
    <bug_when>2014-02-19 13:34:58 -0800</bug_when>
    <thetext>(In reply to comment #0)
&gt; I just ran the static analyser &quot;cppcheck&quot; over the source
&gt; code of webkitgtk-2.3.4
&gt; 
&gt; It said many things, including
&gt; 
&gt; [Source/WebCore/platform/graphics/StringTruncator.cpp:172]: (style) Array index &apos;adjustedStartIndex&apos; is used before limits check.
&gt; 
&gt; Source code is
&gt; 
&gt;     // Strip single character after ellipsis character, when that character is preceded by a space
&gt;     if (adjustedStartIndex &lt; length &amp;&amp; string[adjustedStartIndex] != space
&gt;         &amp;&amp; adjustedStartIndex &lt; length - 1 &amp;&amp; string[adjustedStartIndex + 1] == space)
&gt;         ++adjustedStartIndex;
&gt; 
&gt; Maybe
&gt; 
&gt;     if (adjustedStartIndex &lt; length &amp;&amp; string[adjustedStartIndex] != space
&gt;         &amp;&amp; adjustedStartIndex &gt; 0 &amp;&amp; string[adjustedStartIndex - 1] == space)
&gt; 
&gt; would be better code

I&apos;m unclear how your proposed change would work given the omission of the body of the if-statement.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1958457</commentid>
    <comment_count>2</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2023-05-27 16:05:11 -0700</bug_when>
    <thetext>We still have this code:

https://searchfox.org/wubkat/source/Source/WebCore/platform/graphics/StringTruncator.cpp#178

Do we need to action anything?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1958460</commentid>
    <comment_count>3</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2023-05-27 16:36:57 -0700</bug_when>
    <thetext>I don&apos;t think that any action is needed. Maybe this code can be rewritten to be slightly nicer, but it&apos;s reasonable to only check for buffer overrun here, not for underrun.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>