Closed Bug 2005113 Opened 11 months ago Closed 5 months ago

Assertion failure: size > 0, at /builds/worker/checkouts/gecko/dom/streams/UnderlyingSourceCallbackHelpers.cpp:294

Categories

(Core :: DOM: Streams, defect)

defect

Tracking

()

RESOLVED FIXED
154 Branch
Tracking Status
firefox-esr115 --- wontfix
firefox-esr140 153+ fixed
firefox148 --- wontfix
firefox149 --- wontfix
firefox150 --- wontfix
firefox151 --- wontfix
firefox152 --- wontfix
firefox153 + fixed
firefox154 + fixed

People

(Reporter: tsmith, Assigned: edenchuang)

References

(Blocks 1 open bug)

Details

(5 keywords, Whiteboard: [adv-main153+r][adv-esr140.13+r])

Crash Data

Attachments

(3 external files)

Found with m-c 20251206-508fa9ddcd5d (--enable-debug)

This was found by visiting a live website with a debug build. A Pernosco session is available here: https://pernos.co/debug/5VDiCW_x3c18jtL7DWv02g/index.html

Assertion failure: size > 0, at /builds/worker/checkouts/gecko/dom/streams/UnderlyingSourceCallbackHelpers.cpp:294

#0  MOZ_ReportAssertionFailure (aStr=0x7c1bca9db450 "size > 0", aFilename=0x7c1bca951687 "/builds/worker/checkouts/gecko/dom/streams/UnderlyingSourceCallbackHelpers.cpp", aLine=294) at /builds/worker/workspace/obj-build/dist/include/mozilla/Assertions.h:136
#1  0x00007c1bd2c017f5 in mozilla::dom::InputToReadableStreamAlgorithms::OnInputStreamReady (this=0x7c1bba88e6f0, aStream=aStream@entry=0x7c1bbd874060) at /builds/worker/checkouts/gecko/dom/streams/UnderlyingSourceCallbackHelpers.cpp:294
#2  0x00007c1bd2c0137a in mozilla::dom::InputStreamHolder::OnInputStreamReady (this=<optimized out>, aStream=0x7c1bbd874060) at /builds/worker/checkouts/gecko/dom/streams/UnderlyingSourceCallbackHelpers.cpp:229
#3  0x00007c1bcea9ff3b in mozilla::ipc::DataPipeReceiver::AsyncWait(nsIInputStreamCallback*, unsigned int, unsigned int, nsIEventTarget*)::$_0::operator()() const (this=0x7c1bbecea188) at /builds/worker/checkouts/gecko/ipc/glue/DataPipe.cpp:671
#4  NS_NewCancelableRunnableFunction<mozilla::ipc::DataPipeReceiver::AsyncWait(nsIInputStreamCallback*, unsigned int, unsigned int, nsIEventTarget*)::$_0>(char const*, mozilla::ipc::DataPipeReceiver::AsyncWait(nsIInputStreamCallback*, unsigned int, unsigned int, nsIEventTarget*)::$_0&&)::FuncCancelableRunnable::Run() (this=0x7c1bbecea150) at /builds/worker/checkouts/gecko/xpcom/threads/nsThreadUtils.h:637
#5  0x00007c1bce09cd25 in nsThread::ProcessNextEvent (this=0x7c1bba81c600, aMayWait=<optimized out>, aResult=0x7c1bb766972f) at /builds/worker/checkouts/gecko/xpcom/threads/nsThread.cpp:1158
#6  0x00007c1bce0a34a0 in NS_ProcessNextEvent (aThread=0x7c1bca9db450, aThread@entry=0x7c1bba81c600, aMayWait=false) at /builds/worker/checkouts/gecko/xpcom/threads/nsThreadUtils.cpp:461
#7  0x00007c1bd2b0d815 in mozilla::dom::WorkerPrivate::DoRunLoop (this=0x7c1bc1d4ba00, aCx=0x7c1bc4440800) at /builds/worker/checkouts/gecko/dom/workers/WorkerPrivate.cpp:3988
#8  0x00007c1bd2af03c5 in mozilla::dom::workerinternals::(anonymous namespace)::WorkerThreadPrimaryRunnable::Run (this=0x7c1bba8e6f40) at /builds/worker/checkouts/gecko/dom/workers/RuntimeService.cpp:2311
#9  0x00007c1bce09cd25 in nsThread::ProcessNextEvent (this=0x7c1bba81c600, aMayWait=<optimized out>, aResult=0x7c1bb7669abf) at /builds/worker/checkouts/gecko/xpcom/threads/nsThread.cpp:1158
#10 0x00007c1bce0a34a0 in NS_ProcessNextEvent (aThread=0x7c1bca9db450, aThread@entry=0x7c1bba81c600, aMayWait=true) at /builds/worker/checkouts/gecko/xpcom/threads/nsThreadUtils.cpp:461
#11 0x00007c1bceab9a5b in mozilla::ipc::MessagePumpForNonMainThreads::Run (this=0x7c1bba8e6a80, aDelegate=0x7c1bb7669b80) at /builds/worker/checkouts/gecko/ipc/glue/MessagePump.cpp:329
#12 0x00007c1bcea41fe2 in MessageLoop::RunHandler (this=0x7c1bca9db450) at /builds/worker/checkouts/gecko/ipc/chromium/src/base/message_loop.cc:361
#13 MessageLoop::Run (this=0x7c1bca9db450) at /builds/worker/checkouts/gecko/ipc/chromium/src/base/message_loop.cc:343
#14 0x00007c1bce09894f in nsThread::ThreadFunc (aArg=0x7c1bba82d6e0) at /builds/worker/checkouts/gecko/xpcom/threads/nsThread.cpp:373
#15 0x00007c1be32e13ad in _pt_root (arg=arg@entry=0x7c1bbc5a6700) at /builds/worker/checkouts/gecko/nsprpub/pr/src/pthreads/ptthread.c:191
#16 0x0000599d4ad1e1ed in set_alt_signal_stack_and_start (params=<optimized out>) at /builds/worker/checkouts/gecko/mozglue/interposers/pthread_create_interposer.cpp:81
#17 0x00007c1be309caa4 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:447
#18 0x00007c1be3129a64 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:100

I took a peek, but once I realized there's two threads involved I immediately stopped following what's going on, so don't take my note on the pernosco trace as a sign I'm looking further.

See Also: → 2004304

I've added some comments in the trace. One of the reads is happening because of NS_AsyncCopy happening because of InternalResponse::Clone, while the other is happening in https://searchfox.org/firefox-main/rev/54da8f6bfead7871ca89f2cb18323af5f00d9620/dom/streams/UnderlyingSourceCallbackHelpers.cpp#571-582.

I think this is a bug with streams. nsIInputStream is an iterator-style item, and it appears that InternalResponse::GetUnfilteredBody returns the actual nsIInputStream within the response, so if you start consuming that stream, and then also clone the response object, we can have multiple concurrent reads on the underlying nsIInputStream which is unsafe.

Marking this as private as I could be slightly worried about it potentially being exploitable. It's quite unsafe to be concurrently reading from a nsIInputStream from multiple threads.

TL;DR: InternalResponse::GetUnfilteredBody/GetBody is a destructive operation on the response object (as it returns a mutable nsIInputStream object which can only be used once), and should probably either clear out the nsIInputStream stored within the response object, or should clone it using NS_CloneInputStream, and return a copy.

Leaving a ni? for :eden who might have more context re: the fetch implementation and be able to provide more insight here?

Group: core-security
Flags: needinfo?(echuang)
Group: core-security → dom-core-security
Keywords: sec-moderate

Tyson's going to check this out with a TSAN build to see if we can more deterministically nail it down.

Nothing is reported by a TSan build.

Looks like there's now a top crasher with a similar signature. Potentially a regression?

See Also: → 2006931

Bug 2004304 is also a top crash.

can you cc me there?

Oh sorry, I should have done that.

Site-scout starting reporting both bug 2004304 and bug 2006931 at the same time. When I try to reproduce either while running with rr this bug is the result I get. Without rr visiting URLs from either bug can result either assertion.

(In reply to Tyson Smith [:tsmith] from comment #9)

Site-scout starting reporting both bug 2004304 and bug 2006931 at the same time. When I try to reproduce either while running with rr this bug is the result I get. Without rr visiting URLs from either bug can result either assertion.

Does it mean we have some URLs to try?

Bug 2006931's crash reports have a few desktop reports and every single one of them includes a URL to some video playing page. Doesn't ring any bell to me though 🤔. (One of them is a porn site so be careful when opening.)

if you start consuming that stream, and then also clone the response object

But this is prevented by the spec AFAICT 🤔 (https://fetch.spec.whatwg.org/#dom-request-clone returns early if stream is touched by anyone)

Assignee: nobody → echuang

According to the Pronosco trace, the case is related to the race caused by response.body and response.clone().

The problemic code is

const response = fetch(url, {mode: 'no-cors'}); 
const body = response.body; 
const clonedResponse = response.clone();
response.body.getReader().read() 

Step1: Get an opaque response. Not sure if this is a necessary step, but this makes response.InternalResponse.mWrappedResponse would not be nullptr
Step2: Creating FetchBodyBase::mReadableStreamBody which is bind with response.internalResponse.mWrappedResponse.mBody.
Step3: Creating the clone response and causing response.internalResponse.mWrappedResponse.mBody to be replaced by replacementBody created by NS_CloneInputStream(). Although FetchBodyBase::mReadableStreamBody is not nullptr, we would not use it for clone. We got nullptr for body here, because this
Step 4: reading the ReadableStream, but from the original mBody, causing a read race between reading and cloning.

So, I think the root cause is that ReadableStream did not change the underlying source inputstream after response.clone(). Here are some thoughts to resolved problem, but not sure what is the best since I am not familiar with stream's implementation.

Solution 1: Binding the underlying inputStream for ReadableStream while the read actions really happen.
I am not sure if this can be done easily.

Solution 2: Updating the bound inputStream of ReadableStream if the bound inputStream is cloned to another one.
This might be much easier, but I think this could be error-prone

Kagami, could you give some suggestions about the solution?

Flags: needinfo?(echuang) → needinfo?(krosylight)

Thank you for the diagnosis! Really helpful to see what's going on.

It seems MaybeTeeReadableStreamBody doesn't do anything because the body is a native stream, so it doesn't follow the usual streams path but instead follows some native clone path, where the protection from the streams spec doesn't apply? Teeing should lock the stream, and because we go another path, we don't lock the stream properly and thus response.body.getReader().read() doesn't fail as expected.

You can copypaste this and see it fails because of the lock, but not if the first line is replaced with r = await fetch(location.href).

// we pass a non-native ReadableStream, which makes it enter the usual streams path of teeing
r = new Response(new ReadableStream());
body = r.body;
r.clone();
body.getReader().read()
// Boom! TypeError: ReadableStream.getReader: Cannot get a new reader for a readable stream already locked by another reader.

I think the solution is to lock the stream somewhere around MaybeTeeReadableStreamBody. Does it make sense to you? And maybe we should audit the fetch implementation to align better with the fetch spec (which is written based on streams spec and thus implies the protection from there)...

Flags: needinfo?(krosylight) → needinfo?(echuang)
Attached file (secure) —
Duplicate of this bug: 2006931
Duplicate of this bug: 2004304

Copying crash signatures from duplicate bugs.

Crash Signature: [@ mozilla::dom::InputToReadableStreamAlgorithms::PullFromInputStream]

Copying crash signatures from duplicate bugs.

Crash Signature: [@ mozilla::dom::InputToReadableStreamAlgorithms::PullFromInputStream] → [@ mozilla::dom::InputToReadableStreamAlgorithms::PullFromInputStream] [@ mozilla::ipc::data_pipe_detail::DataPipeBase::ProcessSegmentsInternal]
Pushed by imoraru@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/e177b4eebe1a https://hg.mozilla.org/integration/autoland/rev/86852a2fda35 Revert "Bug 2005113 - Creating FetchBodyBase::mReadableStream with a cloned body. r=saschanaz." for causing wpt crashes.
[task 2026-02-18T20:14:26.121+00:00] 20:14:26     INFO - TEST-START | /fetch/api/response/response-stream-disturbed-5.any.sharedworker.html
[task 2026-02-18T20:14:26.127+00:00] 20:14:26     INFO - Closing window 015e0789-0bc8-4f42-b9a4-4e2bb21911e2
[task 2026-02-18T20:14:26.750+00:00] 20:14:26     INFO - mozcrash Downloading symbols from: https://firefox-ci-tc.services.mozilla.com/api/queue/v1/task/cqph3HjLT7S7AEFM3i7rNw/artifacts/public/build/target.crashreporter-symbols.zip
[task 2026-02-18T20:14:46.387+00:00] 20:14:46     INFO - mozcrash Copy/paste: /builds/worker/fetches/minidump-stackwalk/minidump-stackwalk --symbols-url=https://symbols.mozilla.org/ --cyborg=/builds/worker/workspace/build/blobber_upload_dir/2745a89c-aaaf-22c4-75d4-b629b7556477.json /tmp/tmpfam72ou_/2745a89c-aaaf-22c4-75d4-b629b7556477.dmp /tmp/tmp3ryx4e61
[task 2026-02-18T20:14:50.535+00:00] 20:14:50     INFO - mozcrash Saved minidump as /builds/worker/workspace/build/blobber_upload_dir/2745a89c-aaaf-22c4-75d4-b629b7556477.dmp
[task 2026-02-18T20:14:50.535+00:00] 20:14:50     INFO - mozcrash Saved app info as /builds/worker/workspace/build/blobber_upload_dir/2745a89c-aaaf-22c4-75d4-b629b7556477.extra
[task 2026-02-18T20:14:50.640+00:00] 20:14:50     INFO - PROCESS-CRASH | 2745a89c-aaaf-22c4-75d4-b629b7556477 | MOZ_RELEASE_ASSERT(!link->mProcessingSegment) (Only one thread may be processing a segment at a time) [@ mozilla::ipc::data_pipe_detail::DataPipeBase::ProcessSegmentsInternal(unsigned int, mozilla::FunctionRef<nsresult (mozilla::Span<char, ] | /fetch/api/response/response-stream-disturbed-5.any.sharedworker.html 
Crash Signature: [@ mozilla::dom::InputToReadableStreamAlgorithms::PullFromInputStream] [@ mozilla::ipc::data_pipe_detail::DataPipeBase::ProcessSegmentsInternal] → [@ mozilla::dom::InputToReadableStreamAlgorithms::PullFromInputStream] [@ mozilla::ipc::data_pipe_detail::DataPipeBase::ProcessSegmentsInternal]
Pushed by rperta@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/7e833aa93331 https://hg.mozilla.org/integration/autoland/rev/9a39c93c1e3e Revert "Bug 2005113 - Creating FetchBodyBase::mReadableStream with a cloned body. r=saschanaz." for causing fetch related failures

TEST-UNEXPECTED-TIMEOUT | /fetch/api/response/response-cancel-stream.any.sharedworker.html | Cancelling a loading Response stream - Test timed out

and more failures

TEST-UNEXPECTED-CRASH | /fetch/api/crashtests/huge-fetch.any.html | expected OK

Pushed by abutkovits@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/078865256996 https://hg.mozilla.org/integration/autoland/rev/358101b08172 Revert "Bug 2005113 - Creating FetchBodyBase::mReadableStream with a cloned body. r=saschanaz." for causing failures at huge-fetch.any.serviceworker.html.

TEST-UNEXPECTED-ERROR | /fetch/api/crashtests/huge-fetch.any.serviceworker.html | Traceback (most recent call last):

More variants of the same test fail.

There is an r+ patch which didn't land and no activity in this bug for 2 weeks.
:edenchuang, could you have a look please?
If you still have some work to do, you can add an action "Plan Changes" in Phabricator.
For more information, please visit BugBot documentation.

Flags: needinfo?(krosylight)
Flags: needinfo?(echuang)

Interesting failure...

Flags: needinfo?(krosylight)

On today's tree only the serviceworker variant fails with timeout.

Flags: needinfo?(krosylight)
Pushed by asilaghi@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/c4bae850e728 https://hg.mozilla.org/integration/autoland/rev/95d20f3b998b Revert "Bug 2005113 - Creating FetchBodyBase::mReadableStream with a cloned body. r=saschanaz." for causing wpt failures at fetch/api/crashtests
[task 2026-05-28T14:58:39.563+00:00] 14:58:39     INFO - TEST-START | /fetch/api/crashtests/huge-fetch.any.serviceworker.html
[task 2026-05-28T14:58:39.564+00:00] 14:58:39     INFO - Setting pref layout.disable-pixel-alignment to false
[task 2026-05-28T14:58:39.582+00:00] 14:58:39     INFO - Setting pref layout.css.anchor-positioning.enabled to true
[task 2026-05-28T14:58:39.599+00:00] 14:58:39     INFO - Setting pref network.dns.disableIPv6 to false
[task 2026-05-28T14:58:39.611+00:00] 14:58:39     INFO - Setting pref dom.fetchKeepalive.enabled to true
[task 2026-05-28T14:58:39.645+00:00] 14:58:39     INFO - Setting pref layout.disable-pixel-alignment to true
[task 2026-05-28T14:58:39.694+00:00] 14:58:39     INFO - Setting pref layout.css.anchor-positioning.enabled to true
[task 2026-05-28T14:58:39.724+00:00] 14:58:39     INFO - Setting pref network.dns.disableIPv6 to true
[task 2026-05-28T14:58:39.771+00:00] 14:58:39     INFO - Setting pref dom.fetchKeepalive.enabled to true
[task 2026-05-28T14:58:39.818+00:00] 14:58:39     INFO - Closing window e1b3340b-8a82-4c93-91a2-b20315faf14b
[task 2026-05-28T14:58:39.940+00:00] 14:58:39     INFO - PID 2864 | [Parent 4316, Main Thread] WARNING: NS_ENSURE_SUCCESS(rv, rv) failed with result 0x80004005 (NS_ERROR_FAILURE): file checkouts\gecko\toolkit\components\url-classifier\nsUrlClassifierDBService.cpp:1656
[task 2026-05-28T14:58:39.942+00:00] 14:58:39     INFO - PID 2864 | [Parent 4316, Main Thread] WARNING: NS_ENSURE_SUCCESS(rv, rv) failed with result 0x80004005 (NS_ERROR_FAILURE): file checkouts\gecko\toolkit\components\url-classifier\nsUrlClassifierDBService.cpp:2145
[task 2026-05-28T14:58:40.229+00:00] 14:58:40     INFO - PID 2864 | [Parent 4316, Main Thread] WARNING: NS_ENSURE_TRUE(entry && entry->mInfo->mSharedState.Get()) failed: file checkouts\gecko\docshell\shistory\SessionHistoryEntry.cpp:1147
[task 2026-05-28T14:58:40.264+00:00] 14:58:40     INFO - PID 2864 | [Parent 4316, Main Thread] WARNING: NS_ENSURE_SUCCESS(rv, rv) failed with result 0x80004005 (NS_ERROR_FAILURE): file checkouts\gecko\toolkit\components\url-classifier\nsUrlClassifierDBService.cpp:1656
[task 2026-05-28T14:58:40.266+00:00] 14:58:40     INFO - PID 2864 | [Parent 4316, Main Thread] WARNING: NS_ENSURE_SUCCESS(rv, rv) failed with result 0x80004005 (NS_ERROR_FAILURE): file checkouts\gecko\toolkit\components\url-classifier\nsUrlClassifierDBService.cpp:2145
[task 2026-05-28T14:58:40.466+00:00] 14:58:40     INFO - PID 2864 | [Parent 4316, DOMCacheThread] WARNING: QM_TRY failure (WARNING): '"ToResult(file->Remove( false))" failed with resultCode 0x80520012, resultName NS_ERROR_FILE_NOT_FOUND', file dom\cache\FileUtils.cpp:805
[task 2026-05-28T14:58:40.476+00:00] 14:58:40     INFO - PID 2864 | [Parent 4316, DOMCacheThread] WARNING: QM_TRY failure (WARNING): '"ToResult(file->Remove( false))" failed with resultCode 0x80520012, resultName NS_ERROR_FILE_NOT_FOUND', file dom\cache\FileUtils.cpp:805
[task 2026-05-28T14:58:40.514+00:00] 14:58:40     INFO - PID 2864 | ### XPCOM_MEM_BLOAT_LOG defined -- logging bloat/leaks to C:\Users\task_177997777328750\AppData\Local\Temp\tmplbp_rgpy\runtests_leaks_4444_tab_pid8268.log
[task 2026-05-28T14:58:50.775+00:00] 14:58:50     INFO - PID 2864 | [4316] Assertion failure: ok (initial reserve should succeed), at checkouts\gecko\xpcom\base\nsCycleCollector.cpp:840
[task 2026-05-28T14:58:50.807+00:00] 14:58:50     INFO - PID 2864 | ### ERROR: SymInitialize: Not enough memory resources are available to process this command.
[task 2026-05-28T14:58:50.815+00:00] 14:58:50     INFO - PID 2864 | [4316] Assertion failure: symbolsInitialized, at \builds\worker\checkouts\gecko\mozglue\misc\StackWalk.cpp:420
Pushed by pstanciu@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/5527bf59927b https://hg.mozilla.org/integration/autoland/rev/060080e3eccd Revert "Bug 2005113 - Creating FetchBodyBase::mReadableStream with a cloned body. r=saschanaz." for causing wpt failures @ response-cancel-stream.any.html
Pushed by asilaghi@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/b9f314650e8e https://hg.mozilla.org/integration/autoland/rev/8c59182f51a1 Revert "Bug 2005113 - Creating FetchBodyBase::mReadableStream with a cloned body. r=saschanaz." for causing wpt failures at fetch resource.
TEST-UNEXPECTED-FAIL | /service-workers/cache-storage/cache-put.https.any.worker.html | Cache.put with opaque-filtered HTTP 206 response - promise_test: Unhandled rejection with value: object "TypeError: NetworkError when attempting to fetch resource."
TEST-UNEXPECTED-FAIL | /service-workers/cache-storage/cache-put.https.any.html | Cache.put with opaque-filtered HTTP 206 response - promise_test: Unhandled rejection with value: object "TypeError: NetworkError when attempting to fetch resource."
TEST-UNEXPECTED-FAIL | /service-workers/cache-storage/cache-put.https.any.sharedworker.html | Cache.put with opaque-filtered HTTP 206 response - promise_test: Unhandled rejection with value: object "TypeError: NetworkError when attempting to fetch resource."
Pushed by nfay@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/271fa8423791 https://hg.mozilla.org/integration/autoland/rev/b373891ff0b0 Revert "Bug 2005113 - Creating FetchBodyBase::mReadableStream with a cloned body. r=saschanaz." for causing wpt failures @ response-cancel-stream.any.html

TEST-UNEXPECTED-TIMEOUT | /fetch/api/response/response-cancel-stream.any.worker.html | Cancelling a loading Response stream - Test timed out

and more failures

Pushed by echuang@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/38e360c0d435 https://hg.mozilla.org/integration/autoland/rev/4c5ce338bdf8 Bind FetchBodyBase::mReadableStream to the body stream and rebind it on clone(). r=saschanaz.
Group: dom-core-security → core-security-release
Status: NEW → RESOLVED
Closed: 5 months ago
Resolution: --- → FIXED
Target Milestone: --- → 154 Branch

Please nominate this for Beta and ESR140 uplift when you have a chance.

Flags: needinfo?(echuang)

firefox-beta Uplift Approval Request

  • User impact if declined/Reason for urgency: Users could trigger the assertion in the content process when the website uses response.body and response.clone in a specific sequence.
  • Code covered by automated testing?: yes
  • Fix verified in Nightly?: no
  • Needs manual QE testing?: no
  • Steps to reproduce for manual QE testing:
  • Risk associated with taking this patch: low
  • Explanation of risk level: Basically, it should be low. The patch rebinds the underlying stream of ReadableStream which created by response.body when response.clone() when the response.body is never used/read. Such that it avoids the underlying stream of body being read in two different threads. And this also follows the spec.
  • String changes made/needed?: no
  • Is Android affected?: yes
Attachment #9598212 - Flags: approval-mozilla-beta?
Attached file (secure) —

Create the body ReadableStream from the underlying body input stream directly.
When clone() is called before the stream has been read and the underlying body
is not cloneable, clone() replaces the original input stream; repoint the
existing unread native ReadableStream at the replacement so the original stream
is not read from two places. This keeps native bodies native (cancellation of
an unread stream still tears down the channel, and the consume path keeps
reading the body input stream directly) without teeing native byte streams.

This no longer clones the body when creating the ReadableStream, so it does not
buffer the whole body; restore the huge-fetch crashtest expectations that were
disabled to avoid OOMing the 32-bit process.

Original Revision: https://phabricator.services.mozilla.com/D280568

Attachment #9598212 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
QA Whiteboard: [sec] [uplift] [qa-triage-done-c154/b153]
Flags: needinfo?(echuang)

This still needs an ESR140 uplift request also.

Flags: needinfo?(echuang)
Attached file (secure) —

Create the body ReadableStream from the underlying body input stream directly.
When clone() is called before the stream has been read and the underlying body
is not cloneable, clone() replaces the original input stream; repoint the
existing unread native ReadableStream at the replacement so the original stream
is not read from two places. This keeps native bodies native (cancellation of
an unread stream still tears down the channel, and the consume path keeps
reading the body input stream directly) without teeing native byte streams.

This no longer clones the body when creating the ReadableStream, so it does not
buffer the whole body; restore the huge-fetch crashtest expectations that were
disabled to avoid OOMing the 32-bit process.

Original Revision: https://phabricator.services.mozilla.com/D280568

(cherry picked from commit 38e360c0d435c4bd9b0e45b207877610506433f3)

Attachment #9599206 - Flags: approval-mozilla-esr140?

firefox-esr140 Uplift Approval Request

  • User impact if declined/Reason for urgency: Users could trigger the assertion in the content process when the website uses response.body and response.clone in a specific sequence.
  • Code covered by automated testing?: yes
  • Fix verified in Nightly?: no
  • Needs manual QE testing?: no
  • Steps to reproduce for manual QE testing:
  • Risk associated with taking this patch: low
  • Explanation of risk level: Basically, it should be low. The patch rebinds the underlying stream of ReadableStream which created by response.body when response.clone() when the response.body is never used/read. Such that it avoids the underlying stream of body being read in two different threads. And this also follows the spec.
  • String changes made/needed?: No
  • Is Android affected?: yes
Attachment #9599206 - Flags: approval-mozilla-esr140? → approval-mozilla-esr140+
Flags: needinfo?(echuang)
Whiteboard: [adv-main153+r][adv-esr140.13+r]
Group: core-security-release
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: