<?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>205889</bug_id>
          
          <creation_ts>2020-01-07 14:51:49 -0800</creation_ts>
          <short_desc>Remove LayoutUnit::operator(const float&amp;) to avoid bad results when the LHS is accidentally made an int</short_desc>
          <delta_ts>2025-01-06 09:02:12 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebCore Misc.</component>
          <version>WebKit Local Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=205563</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>EasyFix, GoodFirstBug, InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Daniel Bates">dbates</reporter>
          <assigned_to name="Yulun Wu">yulun_wu</assigned_to>
          <cc>ahmad.saleem792</cc>
    
    <cc>karlcow</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>zalan</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1603806</commentid>
    <comment_count>0</comment_count>
    <who name="Daniel Bates">dbates</who>
    <bug_when>2020-01-07 14:51:49 -0800</bug_when>
    <thetext>In the patch for bug #205563 I moved some code:

[[
...
LayoutUnit logicalWidth = snappedSelectionRect.width();
if (snappedSelectionRect.x() &gt; logicalRight())
    logicalWidth = 0;
else if (snappedSelectionRect.maxX() &gt; logicalRight())
    logicalWidth = logicalRight() - snappedSelectionRect.x();
...
]]

And in the process changed:

LayoutUnit logicalWidth = snappedSelectionRect.width();

to

auto logicalWidth = snappedSelectionRect.width();

As a result logicalWidth was now an int. This led to bad things when &quot;snappedSelectionRect.maxX() &gt; logicalRight()&quot; evaluates to true because we would then compute &quot;logicalRight() - snappedSelectionRect.x()&quot; (which would be a float since logicalRight() is a float) and then integer truncate to assign to logicalWidth.

This bug would have been prevented if LayoutUnit::operator(const float&amp;) did not exist because it would have forced the code to have been written (pre-my move):

[[
...
LayoutUnit logicalWidth = snappedSelectionRect.width();
if (snappedSelectionRect.x() &gt; logicalRight())
    logicalWidth = 0;
else if (snappedSelectionRect.maxX() &gt; logicalRight())
    logicalWidth = LayoutUnit { logicalRight() - snappedSelectionRect.x() };
...
]]

(Notice the explicit constructor call to LayoutUnit in the second branch).

And so if I had then changed LayoutUnit =&gt; auto it would have compile-time failed and I would have seen my mistake because the code would now be trying to illogically assign a LayoutUnit to an int.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2050925</commentid>
    <comment_count>1</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2024-08-06 09:53:01 -0700</bug_when>
    <thetext>https://searchfox.org/wubkat/rev/b36cbce69fddb7da33823f316bd8ead5bebee970/Source/WebCore/rendering/LegacyInlineTextBox.cpp#164

LayoutRect snappedSelectionRect(const LayoutRect&amp; selectionRect, float logicalRight, float selectionTop, float selectionHeight, bool isHorizontal)
{
    auto snappedSelectionRect = enclosingIntRect(selectionRect);
    LayoutUnit logicalWidth = snappedSelectionRect.width();
    if (snappedSelectionRect.x() &gt; logicalRight)
        logicalWidth = 0;
    else if (snappedSelectionRect.maxX() &gt; logicalRight)
        logicalWidth = logicalRight - snappedSelectionRect.x();

    LayoutPoint topPoint;
    LayoutUnit width;
    LayoutUnit height;
    if (isHorizontal) {
        topPoint = LayoutPoint { snappedSelectionRect.x(), selectionTop };
        width = logicalWidth;
        height = selectionHeight;
    } else {
        topPoint = LayoutPoint { selectionTop, snappedSelectionRect.x() };
        width = selectionHeight;
        height = logicalWidth;
    }
    return LayoutRect { topPoint, LayoutSize { width, height } };
}

____

@Alan - it is in `LegacyInline` layout - do we need to do anything here?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2067045</commentid>
    <comment_count>2</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2024-10-10 16:10:25 -0700</bug_when>
    <thetext>(In reply to Ahmad Saleem from comment #1)
&gt; https://searchfox.org/wubkat/rev/b36cbce69fddb7da33823f316bd8ead5bebee970/
&gt; Source/WebCore/rendering/LegacyInlineTextBox.cpp#164
&gt; 
&gt; LayoutRect snappedSelectionRect(const LayoutRect&amp; selectionRect, float
&gt; logicalRight, float selectionTop, float selectionHeight, bool isHorizontal)
&gt; {
&gt;     auto snappedSelectionRect = enclosingIntRect(selectionRect);
&gt;     LayoutUnit logicalWidth = snappedSelectionRect.width();
&gt;     if (snappedSelectionRect.x() &gt; logicalRight)
&gt;         logicalWidth = 0;
&gt;     else if (snappedSelectionRect.maxX() &gt; logicalRight)
&gt;         logicalWidth = logicalRight - snappedSelectionRect.x();
&gt; 
&gt;     LayoutPoint topPoint;
&gt;     LayoutUnit width;
&gt;     LayoutUnit height;
&gt;     if (isHorizontal) {
&gt;         topPoint = LayoutPoint { snappedSelectionRect.x(), selectionTop };
&gt;         width = logicalWidth;
&gt;         height = selectionHeight;
&gt;     } else {
&gt;         topPoint = LayoutPoint { selectionTop, snappedSelectionRect.x() };
&gt;         width = selectionHeight;
&gt;         height = logicalWidth;
&gt;     }
&gt;     return LayoutRect { topPoint, LayoutSize { width, height } };
&gt; }
&gt; 
&gt; ____
&gt; 
&gt; @Alan - it is in `LegacyInline` layout - do we need to do anything here?

Just updating:

logicalWidth = logicalRight - snappedSelectionRect.x();

to 

logicalWidth = LayoutUnit { logicalRight() - snappedSelectionRect.x() };

works.. with `build-webkit --release`.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2067046</commentid>
    <comment_count>3</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2024-10-10 16:10:42 -0700</bug_when>
    <thetext>(In reply to Ahmad Saleem from comment #2)
&gt; (In reply to Ahmad Saleem from comment #1)
&gt; &gt; https://searchfox.org/wubkat/rev/b36cbce69fddb7da33823f316bd8ead5bebee970/
&gt; &gt; Source/WebCore/rendering/LegacyInlineTextBox.cpp#164
&gt; &gt; 
&gt; &gt; LayoutRect snappedSelectionRect(const LayoutRect&amp; selectionRect, float
&gt; &gt; logicalRight, float selectionTop, float selectionHeight, bool isHorizontal)
&gt; &gt; {
&gt; &gt;     auto snappedSelectionRect = enclosingIntRect(selectionRect);
&gt; &gt;     LayoutUnit logicalWidth = snappedSelectionRect.width();
&gt; &gt;     if (snappedSelectionRect.x() &gt; logicalRight)
&gt; &gt;         logicalWidth = 0;
&gt; &gt;     else if (snappedSelectionRect.maxX() &gt; logicalRight)
&gt; &gt;         logicalWidth = logicalRight - snappedSelectionRect.x();
&gt; &gt; 
&gt; &gt;     LayoutPoint topPoint;
&gt; &gt;     LayoutUnit width;
&gt; &gt;     LayoutUnit height;
&gt; &gt;     if (isHorizontal) {
&gt; &gt;         topPoint = LayoutPoint { snappedSelectionRect.x(), selectionTop };
&gt; &gt;         width = logicalWidth;
&gt; &gt;         height = selectionHeight;
&gt; &gt;     } else {
&gt; &gt;         topPoint = LayoutPoint { selectionTop, snappedSelectionRect.x() };
&gt; &gt;         width = selectionHeight;
&gt; &gt;         height = logicalWidth;
&gt; &gt;     }
&gt; &gt;     return LayoutRect { topPoint, LayoutSize { width, height } };
&gt; &gt; }
&gt; &gt; 
&gt; &gt; ____
&gt; &gt; 
&gt; &gt; @Alan - it is in `LegacyInline` layout - do we need to do anything here?
&gt; 
&gt; Just updating:
&gt; 
&gt; logicalWidth = logicalRight - snappedSelectionRect.x();
&gt; 
&gt; to 
&gt; 
&gt; logicalWidth = LayoutUnit { logicalRight() - snappedSelectionRect.x() };
&gt; 
&gt; works.. with `build-webkit --release`.

logicalWidth = LayoutUnit { logicalRight - snappedSelectionRect.x() };</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2085068</commentid>
    <comment_count>4</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2025-01-06 09:02:12 -0800</bug_when>
    <thetext>&lt;rdar://problem/142420106&gt;</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>