From 8cc3ad767c63ebc64d443e0a91c0889d06b79591 Mon Sep 17 00:00:00 2001 From: AstroAir Date: Tue, 18 Nov 2025 13:51:52 +0800 Subject: [PATCH 1/2] chores : Remove deprecated std::codecvt usage - Replace deprecated fs::u8path with fs::path in backend registry - Remove deprecated std::codecvt_utf8 includes and warning suppressions - Add explicit casts for enum bitwise operations to fix C++20 warnings --- examples/common.cpp | 2 -- src/ggml-backend-reg.cpp | 25 ++++++++----------------- tests/test-backend-ops.cpp | 6 +++--- tests/test-interpolate.cpp | 6 +++--- 4 files changed, 14 insertions(+), 25 deletions(-) diff --git a/examples/common.cpp b/examples/common.cpp index 8eb633e58f..02fd9bff0e 100644 --- a/examples/common.cpp +++ b/examples/common.cpp @@ -3,10 +3,8 @@ #include "common.h" #include -#include #include #include -#include #include #include diff --git a/src/ggml-backend-reg.cpp b/src/ggml-backend-reg.cpp index e96b5c403d..e85d146483 100644 --- a/src/ggml-backend-reg.cpp +++ b/src/ggml-backend-reg.cpp @@ -73,15 +73,6 @@ #include "ggml-cann.h" #endif -// disable C++17 deprecation warning for std::codecvt_utf8 -#if defined(__clang__) -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wdeprecated-declarations" -#elif defined(__GNUC__) -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif - namespace fs = std::filesystem; static std::string path_str(const fs::path & path) { @@ -498,36 +489,36 @@ static fs::path get_executable_path() { static fs::path backend_filename_prefix() { #ifdef _WIN32 - return fs::u8path("ggml-"); + return fs::path("ggml-"); #else - return fs::u8path("libggml-"); + return fs::path("libggml-"); #endif } static fs::path backend_filename_extension() { #ifdef _WIN32 - return fs::u8path(".dll"); + return fs::path(".dll"); #else - return fs::u8path(".so"); + return fs::path(".so"); #endif } static ggml_backend_reg_t ggml_backend_load_best(const char * name, bool silent, const char * user_search_path) { // enumerate all the files that match [lib]ggml-name-*.[so|dll] in the search paths - const fs::path name_path = fs::u8path(name); - const fs::path file_prefix = backend_filename_prefix().native() + name_path.native() + fs::u8path("-").native(); + const fs::path name_path = fs::path(name); + const fs::path file_prefix = backend_filename_prefix().native() + name_path.native() + fs::path("-").native(); const fs::path file_extension = backend_filename_extension(); std::vector search_paths; if (user_search_path == nullptr) { #ifdef GGML_BACKEND_DIR - search_paths.push_back(fs::u8path(GGML_BACKEND_DIR)); + search_paths.push_back(fs::path(GGML_BACKEND_DIR)); #endif // default search paths: executable directory, current directory search_paths.push_back(get_executable_path()); search_paths.push_back(fs::current_path()); } else { - search_paths.push_back(fs::u8path(user_search_path)); + search_paths.push_back(fs::path(user_search_path)); } int best_score = 0; diff --git a/tests/test-backend-ops.cpp b/tests/test-backend-ops.cpp index 267bead8c4..ef71b9a849 100644 --- a/tests/test-backend-ops.cpp +++ b/tests/test-backend-ops.cpp @@ -7521,9 +7521,9 @@ static std::vector> make_test_cases_eval() { test_cases.emplace_back(new test_interpolate(GGML_TYPE_F32, {5, 7, 11, 13}, {2, 5, 7, 11}, mode)); } for (ggml_scale_mode mode : {GGML_SCALE_MODE_BILINEAR, GGML_SCALE_MODE_BICUBIC}) { - test_cases.emplace_back(new test_interpolate(GGML_TYPE_F32, {2, 5, 7, 11}, {5, 7, 11, 13}, mode | GGML_SCALE_FLAG_ALIGN_CORNERS)); - test_cases.emplace_back(new test_interpolate(GGML_TYPE_F32, {1, 4, 3, 2}, {2, 8, 3, 2}, mode | GGML_SCALE_FLAG_ALIGN_CORNERS)); - test_cases.emplace_back(new test_interpolate(GGML_TYPE_F32, {4, 1, 3, 2}, {1, 1, 3, 2}, mode | GGML_SCALE_FLAG_ALIGN_CORNERS)); + test_cases.emplace_back(new test_interpolate(GGML_TYPE_F32, {2, 5, 7, 11}, {5, 7, 11, 13}, static_cast(mode) | GGML_SCALE_FLAG_ALIGN_CORNERS)); + test_cases.emplace_back(new test_interpolate(GGML_TYPE_F32, {1, 4, 3, 2}, {2, 8, 3, 2}, static_cast(mode) | GGML_SCALE_FLAG_ALIGN_CORNERS)); + test_cases.emplace_back(new test_interpolate(GGML_TYPE_F32, {4, 1, 3, 2}, {1, 1, 3, 2}, static_cast(mode) | GGML_SCALE_FLAG_ALIGN_CORNERS)); } test_cases.emplace_back(new test_sum()); diff --git a/tests/test-interpolate.cpp b/tests/test-interpolate.cpp index 43d1d0e891..94170cfdf3 100644 --- a/tests/test-interpolate.cpp +++ b/tests/test-interpolate.cpp @@ -140,12 +140,12 @@ int main() { passed &= test_interpolate("upscale_x2_bilinear_align_corners", {2, 2, 1, 1}, input_upscale, {4, 4, 1, 1}, expected_upscale_x2_bilinear_align_corners, - GGML_SCALE_MODE_BILINEAR | GGML_SCALE_FLAG_ALIGN_CORNERS); + static_cast(GGML_SCALE_MODE_BILINEAR) | GGML_SCALE_FLAG_ALIGN_CORNERS); passed &= test_interpolate("upscale_x1_5_bilinear_align_corners", {2, 2, 1, 1}, input_upscale, {2, 3, 1, 1}, expected_upscale_x1_5_bilinear_align_corners, - GGML_SCALE_MODE_BILINEAR | GGML_SCALE_FLAG_ALIGN_CORNERS); + static_cast(GGML_SCALE_MODE_BILINEAR) | GGML_SCALE_FLAG_ALIGN_CORNERS); passed &= test_interpolate("downscale_nearest", {4, 3, 2, 1}, input_downscale, @@ -160,7 +160,7 @@ int main() { passed &= test_interpolate("downscale_bilinear_align_corners", {4, 3, 2, 1}, input_downscale, {3, 2, 2, 1}, expected_downscale_bilinear_align_corners, - GGML_SCALE_MODE_BILINEAR | GGML_SCALE_FLAG_ALIGN_CORNERS); + static_cast(GGML_SCALE_MODE_BILINEAR) | GGML_SCALE_FLAG_ALIGN_CORNERS); return passed ? 0 : 1; } \ No newline at end of file From 3f7113bbe77b729085c507ac967ea4e97b71c8e5 Mon Sep 17 00:00:00 2001 From: AstroAir Date: Wed, 19 Nov 2025 00:33:05 +0800 Subject: [PATCH 2/2] stb_image: fix potential buffer overflow in PNG tRNS chunk parsing - Increase tc and tc16 arrays from size 3 to 4 to handle RGBA images - Add bounds check when writing to tc array to prevent overflow - Extract value to temporary variable for clarity in tRNS parsing loop --- examples/stb_image.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/stb_image.h b/examples/stb_image.h index 5e807a0a6e..e575c4397d 100644 --- a/examples/stb_image.h +++ b/examples/stb_image.h @@ -5079,8 +5079,8 @@ static void stbi__de_iphone(stbi__png *z) static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp) { stbi_uc palette[1024], pal_img_n=0; - stbi_uc has_trans=0, tc[3]={0}; - stbi__uint16 tc16[3]; + stbi_uc has_trans=0, tc[4]={0}; + stbi__uint16 tc16[4]; stbi__uint32 ioff=0, idata_limit=0, i, pal_len=0; int first=1,k,interlace=0, color=0, is_iphone=0; stbi__context *s = z->s; @@ -5163,7 +5163,10 @@ static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp) if (z->depth == 16) { for (k = 0; k < s->img_n; ++k) tc16[k] = (stbi__uint16)stbi__get16be(s); // copy the values as-is } else { - for (k = 0; k < s->img_n; ++k) tc[k] = (stbi_uc)(stbi__get16be(s) & 255) * stbi__depth_scale_table[z->depth]; // non 8-bit images will be larger + for (k = 0; k < s->img_n; ++k) { + stbi_uc value = (stbi_uc)(stbi__get16be(s) & 255) * stbi__depth_scale_table[z->depth]; + if (k < 4) tc[k] = value; + } // non 8-bit images will be larger } } break;