Do not assume urlPtrPos is just after mimeList when reading it #628 (#630)

Fixes #621, #628 and #629.
This commit is contained in:
Jaifroid 2020-07-01 16:53:06 +01:00 committed by GitHub
parent 3429a98776
commit 70d18a288c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -216,12 +216,16 @@ define(['xzdec_wrapper', 'util', 'utf8', 'q', 'zimDirEntry'], function(xz, util,
* @param {File} file The ZIM file (or first file in array of files) from which the MIME type list
* is to be extracted
* @param {Integer} mimeListPos The offset in <file> at which the MIME type list is found
* @param {Integer} urlPtrPos The offset of the byte after the end of the MIME type list in <file>
* @param {Integer} urlPtrPos The offset of URL Pointer List in the archive
* @returns {Promise} A promise for the MIME Type list as a Map
*/
function readMimetypeMap(file, mimeListPos, urlPtrPos) {
var typeMap = new Map;
var size = urlPtrPos - mimeListPos;
// ZIM archives produced since May 2020 relocate the URL Pointer List to the end of the archive
// so we limit the slice size to max 1024 bytes in order to prevent reading the entire archive into an array buffer
// See https://github.com/openzim/libzim/issues/353
size = size > 1024 ? 1024 : size;
return util.readFileSlice(file, mimeListPos, size).then(function (data) {
if (data.subarray) {
var i = 0;