Skip to content

Commit 62e6b43

Browse files
committed
Merge pull request mozilla#2013 from yurydelendik/fix-server-length
Fixing the channel offset value and length given by HTTP headers
2 parents 8ec1476 + 19c62f5 commit 62e6b43

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

extensions/firefox/components/PdfStreamConverter.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -131,29 +131,29 @@ function PdfDataListener(length) {
131131
}
132132

133133
PdfDataListener.prototype = {
134-
set: function PdfDataListener_set(chunk, offset) {
135-
if (this.length < 0) {
136-
var willBeLoaded = this.loaded + chunk.length;
134+
append: function PdfDataListener_append(chunk) {
135+
var willBeLoaded = this.loaded + chunk.length;
136+
if (this.length >= 0 && this.length < willBeLoaded) {
137+
this.length = -1; // reset the length, server is giving incorrect one
138+
}
139+
if (this.length < 0 && this.data.length < willBeLoaded) {
137140
// data length is unknown and new chunk will not fit in the existing
138141
// buffer, resizing the buffer by doubling the its last length
139-
if (this.data.length < willBeLoaded) {
140-
var newLength = this.data.length;
141-
for (; newLength < willBeLoaded; newLength *= 2) {}
142-
var newData = new Uint8Array(newLength);
143-
newData.set(this.data);
144-
this.data = newData;
145-
}
146-
this.data.set(chunk, this.loaded);
147-
this.loaded = willBeLoaded;
148-
} else {
149-
this.data.set(chunk, offset);
150-
this.loaded = offset + chunk.length;
151-
this.onprogress(this.loaded, this.length);
142+
var newLength = this.data.length;
143+
for (; newLength < willBeLoaded; newLength *= 2) {}
144+
var newData = new Uint8Array(newLength);
145+
newData.set(this.data);
146+
this.data = newData;
152147
}
148+
this.data.set(chunk, this.loaded);
149+
this.loaded = willBeLoaded;
150+
if (this.length >= 0)
151+
this.onprogress(this.loaded, this.length);
153152
},
154153
getData: function PdfDataListener_getData() {
155-
var data = this.length >= 0 ? this.data :
156-
this.data.subarray(0, this.loaded);
154+
var data = this.data;
155+
if (this.loaded != data.length)
156+
data = data.subarray(0, this.loaded);
157157
delete this.data; // releasing temporary storage
158158
return data;
159159
},
@@ -462,7 +462,7 @@ PdfStreamConverter.prototype = {
462462

463463
var binaryStream = this.binaryStream;
464464
binaryStream.setInputStream(aInputStream);
465-
this.dataListener.set(binaryStream.readByteArray(aCount), aOffset);
465+
this.dataListener.append(binaryStream.readByteArray(aCount));
466466
},
467467

468468
// nsIRequestObserver::onStartRequest

0 commit comments

Comments
 (0)