<?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>301998</bug_id>
          
          <creation_ts>2025-11-05 00:55:18 -0800</creation_ts>
          <short_desc>Function=(const Function&amp;&amp;) is a footgun in waiting</short_desc>
          <delta_ts>2025-11-12 00:56:11 -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>Web Template Framework</component>
          <version>WebKit Nightly 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=302139</see_also>
          <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="Jean-Yves Avenard [:jya]">jean-yves.avenard</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>cdumez</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2156532</commentid>
    <comment_count>0</comment_count>
    <who name="Jean-Yves Avenard [:jya]">jean-yves.avenard</who>
    <bug_when>2025-11-05 00:55:18 -0800</bug_when>
    <thetext>Today I encountered an issue that is rather problematic.

the code was
```
    ensureOnDispatcherWithConnection([callback = WTFMove(callback)](auto&amp; renderer, auto&amp; connection) {
        assertIsCurrent(queueSingleton());
        renderer.m_hasAvailableVideoFrameCallback = WTFMove(callback);
        connection.send(Messages::RemoteAudioVideoRendererProxyManager::NotifyWhenHasAvailableVideoFrame(renderer.m_identifier, !!renderer.m_hasAvailableVideoFrameCallback), 0);
    });
```

the code crashed with an infinite recursion. At first I was surprised it even compiled as I had forgotten the `mutable` keyword and didn&apos;t expect `renderer.m_hasAvailableVideoFrameCallback = WTFMove(callback);` to even compile.

the stack trace was
```
thread #2, queue = &apos;AudioVideoRendererRemote&apos;, stop reason = EXC_BAD_ACCESS (code=2, address=0x16b1e7fd0)
  * frame #0: 0x0000000131360128 JavaScriptCore`WTF::assertMallocRestrictionForCurrentThreadScope() at MallocCommon.cpp:58
    frame #1: 0x0000000131305994 JavaScriptCore`WTF::fastMalloc(size=16) at FastMalloc.cpp:537:5 [opt]
    frame #2: 0x000000011b5587c8 WebKit`WTF::Detail::CallableWrapperAllocatorBase::operator new(size=16) at Function.h:38:5
    frame #3: 0x000000011f79665c WebKit`std::__1::unique_ptr&lt;WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;, std::__1::default_delete&lt;WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;&gt;&gt; std::__1::make_unique[abi:sn200100]&lt;WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;, WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, 0&gt;(__args=0x00000001190cc1a8) at unique_ptr.h:767:26
    frame #4: 0x000000011f7965a4 WebKit`decltype(auto) WTF::makeUnique&lt;WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;, WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const&gt;(args=0x00000001190cc1a8) at StdLibExtras.h:871:12
    frame #5: 0x000000011f79685c WebKit`WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt;::Function&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const&gt;(this=0x00000001193cf538, callable=0x00000001190cc1a8) at Function.h:80:29
    frame #6: 0x000000011f79677c WebKit`WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt;::Function&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const&gt;(this=0x00000001193cf538, callable=0x00000001190cc1a8) at Function.h:80:130
    frame #7: 0x000000011f796744 WebKit`WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;::CallableWrapper(this=0x00000001193cf530, callable=0x00000001190cc1a8) at Function.h:56:11
    frame #8: 0x000000011f7966a8 WebKit`WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;::CallableWrapper(this=0x00000001193cf530, callable=0x00000001190cc1a8) at Function.h:56:41
    frame #9: 0x000000011f796668 WebKit`std::__1::unique_ptr&lt;WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;, std::__1::default_delete&lt;WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;&gt;&gt; std::__1::make_unique[abi:sn200100]&lt;WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;, WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, 0&gt;(__args=0x00000001190cc1a8) at unique_ptr.h:767:30
    frame #10: 0x000000011f7965a4 WebKit`decltype(auto) WTF::makeUnique&lt;WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;, WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const&gt;(args=0x00000001190cc1a8) at StdLibExtras.h:871:12
    frame #11: 0x000000011f79685c WebKit`WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt;::Function&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const&gt;(this=0x00000001193cf528, callable=0x00000001190cc1a8) at Function.h:80:29
    frame #12: 0x000000011f79677c WebKit`WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt;::Function&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const&gt;(this=0x00000001193cf528, callable=0x00000001190cc1a8) at Function.h:80:130
    frame #13: 0x000000011f796744 WebKit`WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;::CallableWrapper(this=0x00000001193cf520, callable=0x00000001190cc1a8) at Function.h:56:11
    frame #14: 0x000000011f7966a8 WebKit`WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;::CallableWrapper(this=0x00000001193cf520, callable=0x00000001190cc1a8) at Function.h:56:41
    frame #15: 0x000000011f796668 WebKit`std::__1::unique_ptr&lt;WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;, std::__1::default_delete&lt;WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;&gt;&gt; std::__1::make_unique[abi:sn200100]&lt;WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;, WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, 0&gt;(__args=0x00000001190cc1a8) at unique_ptr.h:767:30
    frame #16: 0x000000011f7965a4 WebKit`decltype(auto) WTF::makeUnique&lt;WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;, WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const&gt;(args=0x00000001190cc1a8) at StdLibExtras.h:871:12
    frame #17: 0x000000011f79685c WebKit`WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt;::Function&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const&gt;(this=0x00000001193cf518, callable=0x00000001190cc1a8) at Function.h:80:29
    frame #18: 0x000000011f79677c WebKit`WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt;::Function&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const&gt;(this=0x00000001193cf518, callable=0x00000001190cc1a8) at Function.h:80:130
    frame #19: 0x000000011f796744 WebKit`WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;::CallableWrapper(this=0x00000001193cf510, callable=0x00000001190cc1a8) at Function.h:56:11
    frame #20: 0x000000011f7966a8 WebKit`WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;::CallableWrapper(this=0x00000001193cf510, callable=0x00000001190cc1a8) at Function.h:56:41
    frame #21: 0x000000011f796668 WebKit`std::__1::unique_ptr&lt;WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;, std::__1::default_delete&lt;WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void,
[....] repeat 4000 times
WTF::MediaTime const&amp;, double&gt;&gt;&gt; std::__1::make_unique[abi:sn200100]&lt;WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;, WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, 0&gt;(__args=0x00000001190cc1a8) at unique_ptr.h:767:30
    frame #10480: 0x000000011f7965a4 WebKit`decltype(auto) WTF::makeUnique&lt;WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;, WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const&gt;(args=0x00000001190cc1a8) at StdLibExtras.h:871:12
    frame #10481: 0x000000011f79685c WebKit`WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt;::Function&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const&gt;(this=0x00000001193c8768, callable=0x00000001190cc1a8) at Function.h:80:29
    frame #10482: 0x000000011f79677c WebKit`WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt;::Function&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const&gt;(this=0x00000001193c8768, callable=0x00000001190cc1a8) at Function.h:80:130
    frame #10483: 0x000000011f796744 WebKit`WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;::CallableWrapper(this=0x00000001193c8760, callable=0x00000001190cc1a8) at Function.h:56:11
    frame #10484: 0x000000011f7966a8 WebKit`WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;::CallableWrapper(this=0x00000001193c8760, callable=0x00000001190cc1a8) at Function.h:56:41
    frame #10485: 0x000000011f796668 WebKit`std::__1::unique_ptr&lt;WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;, std::__1::default_delete&lt;WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;&gt;&gt; std::__1::make_unique[abi:sn200100]&lt;WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;, WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, 0&gt;(__args=0x00000001190cc1a8) at unique_ptr.h:767:30
    frame #11128: 0x000000011f7965a4 WebKit`decltype(auto) WTF::makeUnique&lt;WTF::Detail::CallableWrapper&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const, void, WTF::MediaTime const&amp;, double&gt;, WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const&gt;(args=0x00000001190cc1a8) at StdLibExtras.h:871:12
    frame #11129: 0x000000011f79645c WebKit`WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt;&amp; WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt;::operator=&lt;WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt; const&gt;(this=0x00000001192602e0, callable=0x00000001190cc1a8) at Function.h:112:29
    frame #11130: 0x000000011f7963b0 WebKit`_ZZN6WebKit24AudioVideoRendererRemote32notifyWhenHasAvailableVideoFrameEON3WTF8FunctionIFvRKNS1_9MediaTimeEdEEEENK3$_0clIS0_N3IPC10ConnectionEEEDaRT_RT0_(this=0x00000001190cc1a8, renderer=0x0000000119260210, connection=0x0000000119262100) at AudioVideoRendererRemote.cpp:207:51
    frame #11131: 0x000000011f7962d0 WebKit`WTF::Detail::CallableWrapper&lt;WebKit::AudioVideoRendererRemote::notifyWhenHasAvailableVideoFrame(WTF::Function&lt;void (WTF::MediaTime const&amp;, double)&gt;&amp;&amp;)::$_0, void, WebKit::AudioVideoRendererRemote&amp;, IPC::Connection&amp;&gt;::call(this=0x00000001190cc1a0, in=0x0000000119260210, in=0x0000000119262100) at Function.h:59:39
    frame #11132: 0x000000011f7afd90 WebKit`WTF::Function&lt;void (WebKit::AudioVideoRendererRemote&amp;, IPC::Connection&amp;)&gt;::operator()(this=0x00000001190d81d8, in=0x0000000119260210, in=0x0000000119262100) const at Function.h:103:35
    frame #11133: 0x000000011f7afca0 WebKit`WebKit::AudioVideoRendererRemote::ensureOnDispatcherWithConnection(WTF::Function&lt;void (WebKit::AudioVideoRendererRemote&amp;, IPC::Connection&amp;)&gt;&amp;&amp;)::$_0::operator()(this=0x00000001190d81c8) at AudioVideoRendererRemote.cpp:647:9
    frame #11134: 0x000000011f7afb2c WebKit`WTF::Detail::CallableWrapper&lt;WebKit::AudioVideoRendererRemote::ensureOnDispatcherWithConnection(WTF::Function&lt;void (WebKit::AudioVideoRendererRemote&amp;, IPC::Connection&amp;)&gt;&amp;&amp;)::$_0, void&gt;::call(this=0x00000001190d81c0) at Function.h:59:39
    frame #11135: 0x00000001312d7614 JavaScriptCore`WTF::Function&lt;void ()&gt;::operator()(this=0x00000001190cc1b0) const at Function.h:103:35
    frame #11136: 0x00000001314d0c2c JavaScriptCore`WTF::(anonymous namespace)::DispatchWorkItem::operator()(this=0x00000001190cc1b0) at WorkQueueCocoa.cpp:40:25
    frame #11137: 0x00000001314cf85c JavaScriptCore`void WTF::dispatchWorkItem&lt;WTF::(anonymous namespace)::DispatchWorkItem&gt;(dispatchContext=0x00000001190cc1b0) at WorkQueueCocoa.cpp:48:5
    frame #11138: 0x0000000104de14dc libdispatch.dylib`_dispatch_client_callout + 16
    frame #11139: 0x0000000104dcd7bc libdispatch.dylib`_dispatch_lane_serial_drain + 820
    frame #11140: 0x0000000104dce65c libdispatch.dylib`_dispatch_lane_invoke + 440
    frame #11141: 0x0000000104ddc220 libdispatch.dylib`_dispatch_root_queue_drain_deferred_wlh + 664
    frame #11142: 0x0000000104ddb700 libdispatch.dylib`_dispatch_workloop_worker_thread + 752
    frame #11143: 0x0000000104e677e4 libsystem_pthread.dylib`_pthread_wqthread + 292
```

The code for the operator=
Function=(const Function&amp;&amp;) starts with doing
```
    Function&amp; operator=(CallableType&amp;&amp; callable)
    {
        m_callableWrapper = makeUnique&lt;Detail::CallableWrapper&lt;CallableType, Out, In...&gt;&gt;(std::forward&lt;CallableType&gt;(callable));
        return *this;
    }
```
and from there CallableWrapper tries to create a new function and so forth.

It may be best to check that neither CallableType nor FunctionType are const.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2158187</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2025-11-12 00:56:11 -0800</bug_when>
    <thetext>&lt;rdar://problem/164544374&gt;</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>