From 9f4643ac24ec6910115830faf3f74ee564fc7e85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 14 Mar 2019 22:30:37 +0000 Subject: [PATCH] style: Avoid crashing when calling insertRule("@import ...") on a detached sheet. This should unblock the fuzzers for now, though it's not the ideal solution. It's the only reasonably easy solution to unblock them though, I think. We should probably always keep track of the document a stylesheet was associated with. We'll need that for constructible stylesheets anyway. That requires some though on how to get the cycle-collection and such right, though, and I wouldn't be able to write or land that ASAP. Differential Revision: https://phabricator.services.mozilla.com/D23584 --- components/style/stylesheets/rule_parser.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/components/style/stylesheets/rule_parser.rs b/components/style/stylesheets/rule_parser.rs index 44943259b38..a780ebce250 100644 --- a/components/style/stylesheets/rule_parser.rs +++ b/components/style/stylesheets/rule_parser.rs @@ -189,6 +189,13 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> { return Err(input.new_custom_error(StyleParseErrorKind::UnexpectedImportRule)) } + // FIXME(emilio): We should always be able to have a loader + // around! See bug 1533783. + if self.loader.is_none() { + error!("Saw @import rule, but no way to trigger the load"); + return Err(input.new_custom_error(StyleParseErrorKind::UnexpectedImportRule)) + } + let url_string = input.expect_url_or_string()?.as_ref().to_owned(); let url = CssUrl::parse_from_string(url_string, &self.context);