<?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>247562</bug_id>
          
          <creation_ts>2022-11-07 01:13:58 -0800</creation_ts>
          <short_desc>Intl.Locale.prototype.hourCycles leaks empty JSValue to script</short_desc>
          <delta_ts>2022-11-08 19:55:48 -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>JavaScriptCore</component>
          <version>WebKit Local Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Samuel Groß">saelo</reporter>
          <assigned_to name="David Degazio">d_degazio</assigned_to>
          <cc>bfulgham</cc>
    
    <cc>darin</cc>
    
    <cc>d_degazio</cc>
    
    <cc>mark.lam</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>ysuzuki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1910717</commentid>
    <comment_count>0</comment_count>
    <who name="Samuel Groß">saelo</who>
    <bug_when>2022-11-07 01:13:58 -0800</bug_when>
    <thetext>The following program crashes JSC, both local builds from HEAD and in Safari 16.1

    function main() {
      const v24 = new Intl.Locale(&quot;trimEnd&quot;, { &apos;numberingSystem&apos;: &quot;foobar&quot; });
      let empty = v24.hourCycles;
      print(empty);    // use console.log in Safari
    }
    main();

The issue seems to be that the intlLocalePrototypeGetterHourCycles function [1] doesn&apos;t check that the return value of `locale-&gt;hourCycles(globalObject))` isn&apos;t nullptr and so may end up leaking the empty JSValue to script. I&apos;m not sure if this can be abused to cause memory corruption. The empty JSValue is used for a few internal things, for example to indicate holes in Arrays (so if the leaked empty value is assigned to an array element, that will now appear as a hole) or to signal failure cases in C++ code [2]. As such, it may be possible to confuse some other code with this empty value, but I couldn&apos;t find an obvious case where this would then cause memory corruption.

[1] https://github.com/WebKit/WebKit/blob/443de8e8e9716b164f0a25da35e9235efd72d4dd/Source/JavaScriptCore/runtime/IntlLocalePrototype.cpp#L265
[2] https://github.com/WebKit/WebKit/blob/443de8e8e9716b164f0a25da35e9235efd72d4dd/Source/JavaScriptCore/runtime/JSCJSValue.h#L449</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1910718</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-11-07 01:14:12 -0800</bug_when>
    <thetext>&lt;rdar://problem/102031379&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1910785</commentid>
    <comment_count>2</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2022-11-07 08:48:57 -0800</bug_when>
    <thetext>Looking at IntlLocale::hourCycles and other functions in the file I see that not only do they return nullptr, but they do so without using the RELEASE_AND_RETURN macro. I think that is also incorrect.

There are three options here for behavior for these cases returning nullptr:

1) Raise a JavaScript exception. In that case the return value doesn&apos;t matter and an empty value would be OK.
2) Return a JavaScript undefined.
3) Return a JavaScript null.

Not sure whether we should fix this in the bindings or in the IntlLocale class itself.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1910786</commentid>
    <comment_count>3</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2022-11-07 08:50:38 -0800</bug_when>
    <thetext>OK, I studied this more closely. The other places that return nullptr are doing fine because they all raise exceptions. It’s only this one place that has it wrong, when udatpg_open fails.

I believe the correct fix is to add this line of code before the &quot;return nullptr&quot;:

        throwTypeError(globalObject, scope, &quot;invalid locale&quot;_s);</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1910787</commentid>
    <comment_count>4</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2022-11-07 08:53:50 -0800</bug_when>
    <thetext>This code with the mistake was introduced in bug 227830.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1911111</commentid>
    <comment_count>5</comment_count>
    <who name="David Degazio">d_degazio</who>
    <bug_when>2022-11-08 14:48:59 -0800</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/6266</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1911167</commentid>
    <comment_count>6</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2022-11-08 19:55:46 -0800</bug_when>
    <thetext>Committed 256473@main (86fbeb6fcd63): &lt;https://commits.webkit.org/256473@main&gt;

Reviewed commits have been landed. Closing PR #6266 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>