Skip to content

Commit a0561ea

Browse files
lukewarlowtcl3
authored andcommitted
LibWeb: Implement type attribute validation for image loading
This change fixes image loading where unsupported image types are included in the list of source elements.
1 parent a9604ec commit a0561ea

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,33 @@ void HTMLImageElement::restart_the_animation()
932932
}
933933
}
934934

935+
static bool is_supported_image_type(String const& type)
936+
{
937+
if (type.is_empty())
938+
return true;
939+
if (!type.starts_with_bytes("image/"sv, CaseSensitivity::CaseInsensitive))
940+
return false;
941+
// FIXME: These should be derived from ImageDecoder
942+
if (type.equals_ignoring_ascii_case("image/bmp"sv)
943+
|| type.equals_ignoring_ascii_case("image/gif"sv)
944+
|| type.equals_ignoring_ascii_case("image/vnd.microsoft.icon"sv)
945+
|| type.equals_ignoring_ascii_case("image/x-icon"sv)
946+
|| type.equals_ignoring_ascii_case("image/jpeg"sv)
947+
|| type.equals_ignoring_ascii_case("image/jpg"sv)
948+
|| type.equals_ignoring_ascii_case("image/pjpeg"sv)
949+
|| type.equals_ignoring_ascii_case("image/jxl"sv)
950+
|| type.equals_ignoring_ascii_case("image/png"sv)
951+
|| type.equals_ignoring_ascii_case("image/apng"sv)
952+
|| type.equals_ignoring_ascii_case("image/x-png"sv)
953+
|| type.equals_ignoring_ascii_case("image/tiff"sv)
954+
|| type.equals_ignoring_ascii_case("image/tinyvg"sv)
955+
|| type.equals_ignoring_ascii_case("image/webp"sv)
956+
|| type.equals_ignoring_ascii_case("image/svg+xml"sv))
957+
return true;
958+
959+
return false;
960+
}
961+
935962
// https://html.spec.whatwg.org/multipage/images.html#update-the-source-set
936963
static void update_the_source_set(DOM::Element& element)
937964
{
@@ -1041,8 +1068,15 @@ static void update_the_source_set(DOM::Element& element)
10411068
// 7. Parse child's sizes attribute, and let source set's source size be the returned value.
10421069
source_set.m_source_size = parse_a_sizes_attribute(element.document(), child->get_attribute_value(HTML::AttributeNames::sizes));
10431070

1044-
// FIXME: 8. If child has a type attribute, and its value is an unknown or unsupported MIME type, continue to the next child.
1071+
// 8. If child has a type attribute, and its value is an unknown or unsupported MIME type, continue to the next child.
10451072
if (child->has_attribute(HTML::AttributeNames::type)) {
1073+
auto mime_type = child->get_attribute_value(HTML::AttributeNames::type);
1074+
if (is<HTMLImageElement>(element)) {
1075+
if (!is_supported_image_type(mime_type))
1076+
continue;
1077+
}
1078+
1079+
// FIXME: Implement this step for link elements
10461080
}
10471081

10481082
// FIXME: 9. If child has width or height attributes, set el's dimension attribute source to child.

0 commit comments

Comments
 (0)