Type confusion in HTMLSourceElement::AfterSetAttr
- Fixed in 20 days
- Paid in 25 days
- Disclosed after 20 days
Created attachment 8566444
testcase
The issue can be triggered while setting a specific attribute (srcset,sizes,media,type) of a <source> element. When iterating over the sibling elements in order to find an HTMLImageElement this function does only check the tag name and not the namespace:
nsresult
HTMLSourceElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
const nsAttrValue* aValue, bool aNotify)
{
// If we are associated with a <picture> with a valid <img>, notify it of
// responsive parameter changes
nsINode *parent = nsINode::GetParentNode();
if (aNameSpaceID == kNameSpaceID_None &&
(aName == nsGkAtoms::srcset ||
aName == nsGkAtoms::sizes ||
aName == nsGkAtoms::media ||
aName == nsGkAtoms::type) &&
parent && parent->Tag() == nsGkAtoms::picture) {
nsString strVal = aValue ? aValue->GetStringValue() : EmptyString();
// Find all img siblings after this <source> and notify them of the change
nsCOMPtr<nsINode> sibling = AsContent();
while ( (sibling = sibling->GetNextSibling()) ) {
if (sibling->Tag() == nsGkAtoms::img) {
HTMLImageElement *img = static_cast<HTMLImageElement*>(sibling.get());
if (aName == nsGkAtoms::srcset) {
img->PictureSourceSrcsetChanged(AsContent(), strVal, aNotify);
} else if (aName == nsGkAtoms::sizes) {
img->PictureSourceSizesChanged(AsContent(), strVal, aNotify);
} else if (aName == nsGkAtoms::media ||
aName == nsGkAtoms::type) {
img->PictureSourceMediaOrTypeChanged(AsContent(), aNotify);
}
}
}
This results in a cast of an object which isn't an HTMLImageElement to this type. The attached testcase demonstrates this behaviour. ASan output attached as well. ASan detects this as a use-after-free issue.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A critical-severity memory corruption bug in DOM: Core & HTML. Mozilla made it public on 10 March 2015 as CVE-2015-0803.
About Memory corruption
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.