Skip to content

Commit

Permalink
Bug 1792959 - fix SVGImageElement::HasValidDimensions if we're displa…
Browse files Browse the repository at this point in the history
…y:none or not in a document r=emilio,chunmin

Differential Revision: https://phabricator.services.mozilla.com/D159635
  • Loading branch information
longsonr committed Oct 19, 2022
1 parent db9217e commit 4deb645
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
8 changes: 6 additions & 2 deletions dom/media/webcodecs/VideoFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,12 @@ already_AddRefed<VideoFrame> VideoFrame::Constructor(
return nullptr;
}

// Check the image width and height.
if (!aSVGImageElement.HasValidDimensions()) {
aRv.ThrowInvalidStateError("The SVG does not have valid dimensions");
return nullptr;
}

// If the origin of SVGImageElement's image data is not same origin with the
// entry settings object's origin, then throw a SecurityError DOMException.
SurfaceFromElementResult res = nsLayoutUtils::SurfaceFromElement(
Expand All @@ -1279,8 +1285,6 @@ already_AddRefed<VideoFrame> VideoFrame::Constructor(
aRv.ThrowInvalidStateError("The SVG's surface acquisition failed");
return nullptr;
}
// bug 1792959: `aSVGImageElement.HasValidDimensions()` can crash here. Delay
// the image width and height checks to `InitializeFrameWithResourceAndSize`.

if (!aInit.mTimestamp.WasPassed()) {
aRv.ThrowTypeError("Missing timestamp");
Expand Down
16 changes: 10 additions & 6 deletions dom/svg/SVGImageElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,16 @@ already_AddRefed<Path> SVGImageElement::BuildPath(PathBuilder* aBuilder) {
bool SVGImageElement::HasValidDimensions() const {
float width, height;

DebugOnly<bool> ok =
SVGGeometryProperty::ResolveAll<SVGT::Width, SVGT::Height>(this, &width,
&height);
MOZ_ASSERT(ok, "SVGGeometryProperty::ResolveAll failed");

return width > 0 && height > 0;
if (SVGGeometryProperty::ResolveAll<SVGT::Width, SVGT::Height>(this, &width,
&height)) {
return width > 0 && height > 0;
}
// This function might be called for an element in display:none subtree
// (e.g. SMIL animateMotion), we fall back to use SVG attributes.
return (!mLengthAttributes[ATTR_WIDTH].IsExplicitlySet() ||
mLengthAttributes[ATTR_WIDTH].GetAnimValInSpecifiedUnits() > 0) &&
(!mLengthAttributes[ATTR_HEIGHT].IsExplicitlySet() ||
mLengthAttributes[ATTR_HEIGHT].GetAnimValInSpecifiedUnits() > 0);
}

SVGElement::LengthAttributesInfo SVGImageElement::GetLengthInfo() {
Expand Down

0 comments on commit 4deb645

Please sign in to comment.