[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [meek/master] Read data before bailing out in onDataAvailable.
commit 1f88a0e204433d28a33e7df66681bd74f27f3b0a
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date: Sun Feb 22 15:14:07 2015 -0800
Read data before bailing out in onDataAvailable.
https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/NsIStreamListener#onDataAvailable%28%29
says "Your implementation of this method must read exactly aCount bytes
of data before returning."
It's already downloaded, so it doesn't cost much to read it out of the
buffer. Without this, I got "http channel Listener OnDataAvailable
contract violation" in the console. (I had to purposely induce an
overlong download to get it to happen.)
---
firefox/components/main.js | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/firefox/components/main.js b/firefox/components/main.js
index b851d49..0ec6831 100644
--- a/firefox/components/main.js
+++ b/firefox/components/main.js
@@ -434,15 +434,15 @@ MeekHTTPHelper.HttpStreamListener.prototype = {
// https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIStreamListener
onDataAvailable: function(request, context, stream, sourceOffset, length) {
// dump("onDataAvailable " + length + " bytes\n");
- if (this.length + length > 1000000) {
- request.cancel(Components.results.NS_ERROR_ILLEGAL_VALUE);
- return;
- }
this.length += length;
let input = Components.classes["@mozilla.org/binaryinputstream;1"]
.createInstance(Components.interfaces.nsIBinaryInputStream);
input.setInputStream(stream);
this.body.push(String.fromCharCode.apply(null, input.readByteArray(length)));
+ if (this.length > 1000000) {
+ request.cancel(Components.results.NS_ERROR_ILLEGAL_VALUE);
+ return;
+ }
},
};
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits