<?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>43203</bug_id>
          
          <creation_ts>2010-07-29 12:36:24 -0700</creation_ts>
          <short_desc>WebBackForwardList::back/ForwardListWithLimit() crashes if passed a limit larger than max int</short_desc>
          <delta_ts>2010-07-29 14:36:06 -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>WebKit2</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</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="John Sullivan">sullivan</reporter>
          <assigned_to name="John Sullivan">sullivan</assigned_to>
          <cc>aroben</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>257811</commentid>
    <comment_count>0</comment_count>
    <who name="John Sullivan">sullivan</who>
    <bug_when>2010-07-29 12:36:24 -0700</bug_when>
    <thetext>WebBackForwardList::backListWithLimit() and forwardListWithLimit() crash if the limit parameter, an unsigned value, is larger than numeric_limits&lt;int&gt;::max().

The crash occurs here, with i == 0 but an empty m_entries:

        WebBackForwardListItem* item = m_entries[i].get();


The crash occurs due to this incorrect logic:

    unsigned size = std::min(backListCount(), static_cast&lt;unsigned&gt;(limit));
    if (!size)
        return ImmutableArray::create();

This is attempting to return early for the empty case, but casting the unsigned limit to an int can make it negative, and thus size is negative, and thus the test for !size fails.

I&apos;ve got a fix that I&apos;ll send out after lunch, if nobody beats me to it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>257863</commentid>
    <comment_count>1</comment_count>
      <attachid>62989</attachid>
    <who name="John Sullivan">sullivan</who>
    <bug_when>2010-07-29 13:59:53 -0700</bug_when>
    <thetext>Created attachment 62989
Patch to cast to unsigned rather than int, to avoid wrapping</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>257869</commentid>
    <comment_count>2</comment_count>
      <attachid>62989</attachid>
    <who name="Adam Roben (:aroben)">aroben</who>
    <bug_when>2010-07-29 14:06:05 -0700</bug_when>
    <thetext>Comment on attachment 62989
Patch to cast to unsigned rather than int, to avoid wrapping

&gt; -    unsigned size = std::min(backListCount(), static_cast&lt;int&gt;(limit));
&gt; +    unsigned size = std::min(static_cast&lt;unsigned&gt;(backListCount()), limit);

Why does backListCount return an int? Seems like it should return unsigned.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>257882</commentid>
    <comment_count>3</comment_count>
    <who name="John Sullivan">sullivan</who>
    <bug_when>2010-07-29 14:24:41 -0700</bug_when>
    <thetext>I agree that backForwardCount() should not return an int. Probably all of these functions should deal with size_t&apos;s. But I didn&apos;t want to get into that territory for this fix.

Checked in as http://trac.webkit.org/changeset/64306</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>257894</commentid>
    <comment_count>4</comment_count>
    <who name="John Sullivan">sullivan</who>
    <bug_when>2010-07-29 14:36:06 -0700</bug_when>
    <thetext>I filed a bug about the inconsistent use of types in this area: &lt;https://bugs.webkit.org/show_bug.cgi?id=43214&gt;</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>62989</attachid>
            <date>2010-07-29 13:59:53 -0700</date>
            <delta_ts>2010-07-29 14:06:05 -0700</delta_ts>
            <desc>Patch to cast to unsigned rather than int, to avoid wrapping</desc>
            <filename>backListCastingPatch.txt</filename>
            <type>text/plain</type>
            <size>1812</size>
            <attacher name="John Sullivan">sullivan</attacher>
            
              <data encoding="base64">SW5kZXg6IFdlYktpdDIvQ2hhbmdlTG9nCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIFdlYktpdDIvQ2hhbmdlTG9n
CShyZXZpc2lvbiA2NDMwNCkKKysrIFdlYktpdDIvQ2hhbmdlTG9nCSh3b3JraW5nIGNvcHkpCkBA
IC0xLDMgKzEsMTYgQEAKKzIwMTAtMDctMjkgIEpvaG4gU3VsbGl2YW4gIDxzdWxsaXZhbkBhcHBs
ZS5jb20+CisKKyAgICAgICAgPGh0dHBzOi8vYnVncy53ZWJraXQub3JnL3Nob3dfYnVnLmNnaT9p
ZD00MzIwMz4KKyAgICAgICAgV2ViQmFja0ZvcndhcmRMaXN0OjpiYWNrL0ZvcndhcmRMaXN0V2l0
aExpbWl0KCkgY3Jhc2hlcyBpZiBwYXNzZWQgYSBsaW1pdCBsYXJnZXIgdGhhbiBtYXggaW50CisK
KyAgICAgICAgUmV2aWV3ZWQgYnkgTk9CT0RZIChPT1BTISkuCisKKyAgICAgICAgKiBVSVByb2Nl
c3MvV2ViQmFja0ZvcndhcmRMaXN0LmNwcDoKKyAgICAgICAgKFdlYktpdDo6V2ViQmFja0Zvcndh
cmRMaXN0OjpiYWNrTGlzdEFzSW1tdXRhYmxlQXJyYXlXaXRoTGltaXQpOgorICAgICAgICBGaXhl
ZCBjYXN0aW5nIHNvIHRoYXQgYSBsYXJnZSB1bnNpZ25lZCB3b24ndCBiZWNvbWUgYSBuZWdhdGl2
ZSBpbnQuCisgICAgICAgIChXZWJLaXQ6OldlYkJhY2tGb3J3YXJkTGlzdDo6Zm9yd2FyZExpc3RB
c0ltbXV0YWJsZUFycmF5V2l0aExpbWl0KToKKyAgICAgICAgRGl0dG8uCisKIDIwMTAtMDctMjkg
IEFuZGVycyBDYXJsc3NvbiAgPGFuZGVyc2NhQGFwcGxlLm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bmVkIGxpbWl0KQogewot
ICAgIHVuc2lnbmVkIHNpemUgPSBzdGQ6Om1pbihmb3J3YXJkTGlzdENvdW50KCksIHN0YXRpY19j
YXN0PGludD4obGltaXQpKTsKKyAgICB1bnNpZ25lZCBzaXplID0gc3RkOjptaW4oc3RhdGljX2Nh
c3Q8dW5zaWduZWQ+KGZvcndhcmRMaXN0Q291bnQoKSksIGxpbWl0KTsKICAgICBpZiAoIXNpemUp
CiAgICAgICAgIHJldHVybiBJbW11dGFibGVBcnJheTo6Y3JlYXRlKCk7CiAK
</data>
<flag name="review"
          id="51266"
          type_id="1"
          status="+"
          setter="sam"
    />
          </attachment>
      

    </bug>

</bugzilla>