Closed Bug 1355334 Opened 7 years ago Closed 7 years ago

Exception in XPIProvider when manifest validation fails

Categories

(Toolkit :: Add-ons Manager, enhancement, P2)

enhancement

Tracking

()

RESOLVED FIXED
2012-10-25
Tracking Status
firefox55 --- fixed

People

(Reporter: aswan, Assigned: aswan)

Details

(Whiteboard: triaged)

Attachments

(1 file)

When attempting to install a webextension that fails manifest validation we now get this uncaught exception:

A coding exception was thrown and uncaught in a Task.

Full message: TypeError: manifest is undefined
Full stack: loadManifestFromWebManifest<@resource://gre/modules/addons/XPIProvider.jsm:966:16
...

I think this was introduced by a combination of bug 1330349 and bug 1344590.  Prior to either of those bugs, loadManifestFromWebManifest() checked extension.errors before looking at the returned manifest.  Bug 1330349 added code that looks at manifest.theme before checking whether the manifest is valid, but this worked by accident (since ExtensionData.loadManifest() used to return the non-normalized parsed manifest json if validation failed).  But 1344590 changes loadManifest() to sensibly return undefined if validation fails, so now the code added with bug 1330349 blows up.
Comment on attachment 8856805 [details]
Bug 1355334 Bail out immediately on manifest errors when parsing a webextension

https://reviewboard.mozilla.org/r/128730/#review131240

::: toolkit/mozapps/extensions/internal/XPIProvider.jsm:990
(Diff revision 1)
>    }
>  
>    let addon = new AddonInternal();
>    addon.id = bss.id;
>    addon.version = manifest.version;
> -  addon.type = "webextension" + (theme ? "-theme" : "");
> +  addon.type = "webextension" + (!!manifest.theme ? "-theme" : "");

Nit: No need for `!!`. Don't we have an ESLint rule for this?
Attachment #8856805 - Flags: review?(kmaglione+bmo) → review+
Priority: -- → P2
Whiteboard: triaged
Target Milestone: --- → 2012-10-25
Assignee: nobody → aswan
Pushed by aswan@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/6b3a538e17a1
Bail out immediately on manifest errors when parsing a webextension r=kmag
Comment on attachment 8856805 [details]
Bug 1355334 Bail out immediately on manifest errors when parsing a webextension

https://reviewboard.mozilla.org/r/128730/#review131592

::: toolkit/mozapps/extensions/internal/XPIProvider.jsm:969
(Diff revision 2)
>    let manifest = yield extension.loadManifest();
> -  let theme = !!manifest.theme;
>  
> +  // If there were any errors loading the extension, bail out now.
> +  if (extension.errors.length) {
> +    throw new Error("Extension is invalid");

Urgh. Mozreview. Sorry, apparently I lost a comment.

We need to do this after `initAllLocales`, or locale errors won't cause the installation to fail. We could also do it *before* the locale initialization, but then developers would have to fix all manifest errors before they learn about locale errors, which would be unfortunate.

I thought we had tests for this, but I guess nothing fails after these changes?
Comment on attachment 8856805 [details]
Bug 1355334 Bail out immediately on manifest errors when parsing a webextension

https://reviewboard.mozilla.org/r/128730/#review131668

::: toolkit/mozapps/extensions/internal/XPIProvider.jsm:969
(Diff revision 2)
>    let manifest = yield extension.loadManifest();
> -  let theme = !!manifest.theme;
>  
> +  // If there were any errors loading the extension, bail out now.
> +  if (extension.errors.length) {
> +    throw new Error("Extension is invalid");

But after your recent changes, ExtensionData.manifest is null (or undefined, i don't remember which) if normalization fails so we can't check locales, that requires the default_locale property from the manifest...
Pushed by aswan@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/4045456954bd
Bail out immediately on manifest errors when parsing a webextension r=kmag
We just need to check whether `this.manifest` is null from the `defaultLocale` getter.
(In reply to Kris Maglione [:kmag] from comment #10)
> We just need to check whether `this.manifest` is null from the
> `defaultLocale` getter.

This comment crossed mid-air with a push of a different fix.
We can change it in a followup if you like, but I think that saying you can't call initAllLocales() if you don't have a valid manifest is a reasonable thing...
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: