Commit eeead6da authored by Romain Courteaud's avatar Romain Courteaud

[indexeddb] Fix getAttachment with huge blob

The array buffer length was higher than what is stored in indexedDB

Thanks to Alexandra Rogova for reporting the issue.
parent 5692bfb1
...@@ -474,8 +474,7 @@ ...@@ -474,8 +474,7 @@
var index = parseInt( var index = parseInt(
cursor.primaryKey.slice(key_path.length + 1), cursor.primaryKey.slice(key_path.length + 1),
10 10
), );
i;
if ((start !== 0) && (index < start_index)) { if ((start !== 0) && (index < start_index)) {
// No need to fetch blobs at the start // No need to fetch blobs at the start
...@@ -486,12 +485,6 @@ ...@@ -486,12 +485,6 @@
return; return;
} }
i = index - start_index;
// Extend array size
while (i > promise_list.length) {
promise_list.push(null);
i -= 1;
}
// Sort the blob by their index // Sort the blob by their index
promise_list.splice( promise_list.splice(
index - start_index, index - start_index,
...@@ -548,13 +541,8 @@ ...@@ -548,13 +541,8 @@
var index = parseInt( var index = parseInt(
cursor.primaryKey.slice(key_path.length + 1), cursor.primaryKey.slice(key_path.length + 1),
10 10
), );
i = index;
// Extend array size
while (i > array_buffer_list.length) {
array_buffer_list.push(null);
i -= 1;
}
// Sort the blob by their index // Sort the blob by their index
array_buffer_list.splice( array_buffer_list.splice(
index, index,
......
...@@ -20,10 +20,10 @@ ...@@ -20,10 +20,10 @@
/*jslint nomen: true */ /*jslint nomen: true */
/*global indexedDB, Blob, sinon, IDBDatabase, /*global indexedDB, Blob, sinon, IDBDatabase,
IDBTransaction, IDBIndex, IDBObjectStore, IDBCursor, IDBKeyRange, IDBTransaction, IDBIndex, IDBObjectStore, IDBCursor, IDBKeyRange,
DOMException*/ DOMException, Rusha*/
(function (jIO, QUnit, indexedDB, Blob, sinon, IDBDatabase, (function (jIO, QUnit, indexedDB, Blob, sinon, IDBDatabase,
IDBTransaction, IDBIndex, IDBObjectStore, IDBCursor, IDBKeyRange, IDBTransaction, IDBIndex, IDBObjectStore, IDBCursor, IDBKeyRange,
DOMException) { DOMException, Rusha) {
"use strict"; "use strict";
var test = QUnit.test, var test = QUnit.test,
stop = QUnit.stop, stop = QUnit.stop,
...@@ -34,12 +34,9 @@ ...@@ -34,12 +34,9 @@
equal = QUnit.equal, equal = QUnit.equal,
module = QUnit.module, module = QUnit.module,
throws = QUnit.throws, throws = QUnit.throws,
big_string = "", big_string = "";
j;
for (j = 0; j < 3000000; j += 1) { big_string = new Array(3000000).fill('a').join('');
big_string += "a";
}
function deleteIndexedDB(storage) { function deleteIndexedDB(storage) {
return new RSVP.Promise(function resolver(resolve, reject) { return new RSVP.Promise(function resolver(resolve, reject) {
...@@ -1692,6 +1689,46 @@ ...@@ -1692,6 +1689,46 @@
}); });
}); });
test("get huge attachment", function () {
var context = this,
attachment = "attachment";
stop();
expect(4);
deleteIndexedDB(context.jio)
.then(function () {
return context.jio.put("foo", {"title": "bar"});
})
.then(function () {
return context.jio.putAttachment(
"foo",
attachment,
new Blob([new Array(11 * 2000000).fill('a').join('')],
{type: 'text/fooplain'})
);
})
.then(function () {
return context.jio.getAttachment("foo", attachment);
})
.then(function (blob) {
ok(blob instanceof Blob, "Data is Blob");
equal(blob.type, 'text/fooplain');
equal(blob.size, 22000000);
return jIO.util.readBlobAsArrayBuffer(blob);
})
.then(function (result) {
equal((new Rusha()).digestFromArrayBuffer(result.target.result),
'6f510194afd8e436d00a543f49a7df09e86c2687');
})
.fail(function (error) {
ok(false, error);
})
.always(function () {
start();
});
});
test("retrieve empty blob", function () { test("retrieve empty blob", function () {
var context = this, var context = this,
attachment = "attachment", attachment = "attachment",
...@@ -2017,4 +2054,4 @@ ...@@ -2017,4 +2054,4 @@
}(jIO, QUnit, indexedDB, Blob, sinon, IDBDatabase, }(jIO, QUnit, indexedDB, Blob, sinon, IDBDatabase,
IDBTransaction, IDBIndex, IDBObjectStore, IDBCursor, IDBKeyRange, IDBTransaction, IDBIndex, IDBObjectStore, IDBCursor, IDBKeyRange,
DOMException)); DOMException, Rusha));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment