summaryrefslogtreecommitdiffstats
path: root/dom/fetch/FetchDriver.cpp
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-10-21 23:48:32 +0000
committerMoonchild <moonchild@palemoon.org>2020-10-24 10:38:21 +0000
commit10bf4a6d5b651141171e648fde1b0ba25a87d37d (patch)
tree21f8760ec3e328af66e15f449217bf7a2f91e874 /dom/fetch/FetchDriver.cpp
parentc3778db14df34e88bfd3663b2b3fb54ead633402 (diff)
downloadUXP-10bf4a6d5b651141171e648fde1b0ba25a87d37d.tar
UXP-10bf4a6d5b651141171e648fde1b0ba25a87d37d.tar.gz
UXP-10bf4a6d5b651141171e648fde1b0ba25a87d37d.tar.lz
UXP-10bf4a6d5b651141171e648fde1b0ba25a87d37d.tar.xz
UXP-10bf4a6d5b651141171e648fde1b0ba25a87d37d.zip
[DOM Fetch] Detect broken pipes and propagate that write error to the caller.
Diffstat (limited to 'dom/fetch/FetchDriver.cpp')
-rw-r--r--dom/fetch/FetchDriver.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/dom/fetch/FetchDriver.cpp b/dom/fetch/FetchDriver.cpp
index d028ffdba..14c000121 100644
--- a/dom/fetch/FetchDriver.cpp
+++ b/dom/fetch/FetchDriver.cpp
@@ -772,6 +772,17 @@ FetchDriver::OnDataAvailable(nsIRequest* aRequest,
nsresult rv = aInputStream->ReadSegments(NS_CopySegmentToStream,
mPipeOutputStream,
aCount, &aRead);
+
+ // If no data was read, it's possible the output stream is closed but the
+ // ReadSegments call followed its contract of returning NS_OK despite write
+ // errors. Unfortunately, nsIOutputStream has an ill-conceived contract when
+ // taken together with ReadSegments' contract, because the pipe will just
+ // NS_OK if we try and invoke its Write* functions ourselves with a 0 count.
+ // So we must just assume the pipe is broken.
+ if (aRead == 0 && aCount != 0) {
+ return NS_BASE_STREAM_CLOSED;
+ }
+
return rv;
}