Bug 1668372 - Escape URI GMP zips are extracted from. r=Gijs

Users with certain special characters on the path to the temp dirs where GMPs
are saved would not be able to extract GMPS. This fixes this by escaping
characters such as # so that the URIs to the file are treated correctly.

Differential Revision: https://phabricator.services.mozilla.com/D92088
This commit is contained in:
Bryce Seager van Dyk 2020-10-01 22:17:06 +00:00
Родитель dbe64bb4b5
Коммит bf659512f8
2 изменённых файлов: 17 добавлений и 5 удалений

Просмотреть файл

@ -13,7 +13,9 @@ const FILE_ENTRY = "201: ";
onmessage = async function(msg) {
try {
let extractedPaths = [];
let jarPath = "jar:file://" + msg.data.zipPath + "!/";
// Construct a jar URI from the file URI so we can use the JAR URI scheme
// handling to navigate inside the zip file.
let jarPath = "jar:" + msg.data.zipURI + "!/";
let jarResponse = await fetch(jarPath);
let dirListing = await jarResponse.text();
let lines = dirListing.split("\n");

Просмотреть файл

@ -34,6 +34,11 @@ ChromeUtils.defineModuleGetter(
"CertUtils",
"resource://gre/modules/CertUtils.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"FileUtils",
"resource://gre/modules/FileUtils.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"UpdateUtils",
@ -506,8 +511,10 @@ GMPAddon.prototype = {
};
/**
* Constructs a GMPExtractor object which is used to extract a GMP zip
* into the specified location. (Which typically leties per platform)
* into the specified location.
* @param zipPath The path on disk of the zip file to extract
* @param relativePath The relative path inside the profile directory to
* extract the zip to.
*/
function GMPExtractor(zipPath, relativeInstallPath) {
this.zipPath = zipPath;
@ -525,6 +532,9 @@ GMPExtractor.prototype = {
this._deferred = PromiseUtils.defer();
let deferredPromise = this._deferred;
let { zipPath, relativeInstallPath } = this;
// Escape the zip path since the worker will use it as a URI
let zipFile = new FileUtils.File(zipPath);
let zipURI = Services.io.newFileURI(zipFile).spec;
let worker = new ChromeWorker(
"resource://gre/modules/GMPExtractorWorker.js"
);
@ -532,17 +542,17 @@ GMPExtractor.prototype = {
let log = getScopedLogger("GMPExtractor");
worker.terminate();
if (msg.data.result != "success") {
log.error("Failed to extract zip file: " + zipPath);
log.error("Failed to extract zip file: " + zipURI);
return deferredPromise.reject({
target: this,
status: msg.data.exception,
type: "exception",
});
}
log.info("Successfully extracted zip file: " + zipPath);
log.info("Successfully extracted zip file: " + zipURI);
return deferredPromise.resolve(msg.data.extractedPaths);
};
worker.postMessage({ zipPath, relativeInstallPath });
worker.postMessage({ zipURI, relativeInstallPath });
return this._deferred.promise;
},
};