Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when loading SVG imported as Image #90573

Merged
merged 1 commit into from
Apr 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions modules/svg/image_loader_svg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,17 @@ void ImageLoaderSVG::get_recognized_extensions(List<String> *p_extensions) const
}

Error ImageLoaderSVG::load_image(Ref<Image> p_image, Ref<FileAccess> p_fileaccess, BitField<ImageFormatLoader::LoaderFlags> p_flags, float p_scale) {
String svg = p_fileaccess->get_as_utf8_string();
const uint64_t len = p_fileaccess->get_length() - p_fileaccess->get_position();
Vector<uint8_t> buffer;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's possible to have length < -1 or >= p_fileaccess->get_length(), so we don't need a err index check but..

Copy link
Member

@fire fire Apr 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However it is missing is_null checks on the inputs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which input do you mean? Null checks for p_image and p_fileaccess are done at ImageLoader::load_image() level.

buffer.resize(len);
p_fileaccess->get_buffer(buffer.ptrw(), buffer.size());

String svg;
Error err = svg.parse_utf8((const char *)buffer.ptr(), buffer.size());
if (err != OK) {
return err;
}

Error err;
if (p_flags & FLAG_CONVERT_COLORS) {
err = create_image_from_string(p_image, svg, p_scale, false, forced_color_map);
} else {
Expand Down
Loading