Skip to content

Commit b30c355

Browse files
authored
Merge pull request #566 from Spartan322/fix/unsafe-image-loading
Fix potential crash on corrupted/missing dds file
2 parents 89c9436 + d397e21 commit b30c355

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

extension/src/openvic-extension/utility/Utilities.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,10 @@ Ref<Resource> Utilities::load_resource(String const& path, String const& type_hi
187187
}
188188

189189
static Ref<Image> load_dds_image(String const& path) {
190-
gli::texture2d texture { gli::load_dds(Utilities::godot_to_std_string(path)) };
191-
ERR_FAIL_COND_V_MSG(texture.empty(), nullptr, Utilities::format("Failed to load DDS file: %s", path));
190+
const gli::texture dds_file = gli::load_dds(Utilities::godot_to_std_string(path));
191+
ERR_FAIL_COND_V_MSG(dds_file.empty(), nullptr, Utilities::format("Failed to load DDS file: %s", path));
192+
gli::texture2d texture { dds_file };
193+
ERR_FAIL_COND_V_MSG(texture.empty(), nullptr, Utilities::format("Failed to create DDS texture: %s", path));
192194

193195
static constexpr gli::format expected_format = gli::FORMAT_BGRA8_UNORM_PACK8;
194196
const bool needs_bgr_to_rgb = texture.format() == expected_format;

0 commit comments

Comments
 (0)