Commit 489454c7 for libheif
commit 489454c70a47e38b98f2ad803c289e618c75e43c
Author: Dirk Farin <dirk.farin@gmail.com>
Date: Thu Aug 27 00:36:51 2026 +0200
tests: avoid a GCC 13 stringop-overflow false positive in append_fourcc
With GCC 13 (Ubuntu 24.04) and -O3, `out.insert(out.end(), fourcc, fourcc + 4)`
on a std::vector<uint8_t> triggers
stl_algobase.h:388:25: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
inside the inlined range insert, which fails the test build with
-Werror. The warning is spurious; GCC cannot see that the vector was
grown before the copy. Append the four bytes with push_back instead.
The helper is duplicated in six test files, all of which are changed.
diff --git a/tests/decompression_bomb.cc b/tests/decompression_bomb.cc
index 8fdd8499..db1c157a 100644
--- a/tests/decompression_bomb.cc
+++ b/tests/decompression_bomb.cc
@@ -58,7 +58,11 @@ void put_u16_be(std::vector<uint8_t>& out, uint16_t v) {
}
void append_fourcc(std::vector<uint8_t>& out, const char fourcc[4]) {
- out.insert(out.end(), fourcc, fourcc + 4);
+ // Append the bytes one at a time. A range insert from the char array makes
+ // GCC 13 report a bogus -Wstringop-overflow in optimized builds.
+ for (int i = 0; i < 4; i++) {
+ out.push_back(static_cast<uint8_t>(fourcc[i]));
+ }
}
// Append a null-terminated string (as read by Box_infe via read_string()).
diff --git a/tests/entity_groups.cc b/tests/entity_groups.cc
index 1da900f2..1e745a83 100644
--- a/tests/entity_groups.cc
+++ b/tests/entity_groups.cc
@@ -47,7 +47,11 @@ void put_u16_be(std::vector<uint8_t>& out, uint16_t v) {
}
void append_fourcc(std::vector<uint8_t>& out, const char fourcc[4]) {
- out.insert(out.end(), fourcc, fourcc + 4);
+ // Append the bytes one at a time. A range insert from the char array makes
+ // GCC 13 report a bogus -Wstringop-overflow in optimized builds.
+ for (int i = 0; i < 4; i++) {
+ out.push_back(static_cast<uint8_t>(fourcc[i]));
+ }
}
std::vector<uint8_t> make_box(const char fourcc[4],
diff --git a/tests/grid_tile_missing.cc b/tests/grid_tile_missing.cc
index b0025424..de55dcaf 100644
--- a/tests/grid_tile_missing.cc
+++ b/tests/grid_tile_missing.cc
@@ -46,7 +46,11 @@ void put_u16_be(std::vector<uint8_t>& out, uint16_t v) {
}
void append_fourcc(std::vector<uint8_t>& out, const char fourcc[4]) {
- out.insert(out.end(), fourcc, fourcc + 4);
+ // Append the bytes one at a time. A range insert from the char array makes
+ // GCC 13 report a bogus -Wstringop-overflow in optimized builds.
+ for (int i = 0; i < 4; i++) {
+ out.push_back(static_cast<uint8_t>(fourcc[i]));
+ }
}
void append(std::vector<uint8_t>& out, const std::vector<uint8_t>& v) {
diff --git a/tests/iden_declared_size.cc b/tests/iden_declared_size.cc
index 47941698..368f3e47 100644
--- a/tests/iden_declared_size.cc
+++ b/tests/iden_declared_size.cc
@@ -45,7 +45,11 @@ void put_u16_be(std::vector<uint8_t>& out, uint16_t v) {
}
void append_fourcc(std::vector<uint8_t>& out, const char fourcc[4]) {
- out.insert(out.end(), fourcc, fourcc + 4);
+ // Append the bytes one at a time. A range insert from the char array makes
+ // GCC 13 report a bogus -Wstringop-overflow in optimized builds.
+ for (int i = 0; i < 4; i++) {
+ out.push_back(static_cast<uint8_t>(fourcc[i]));
+ }
}
void append(std::vector<uint8_t>& out, const std::vector<uint8_t>& v) {
diff --git a/tests/overlay_amplification.cc b/tests/overlay_amplification.cc
index c85e4502..833808f6 100644
--- a/tests/overlay_amplification.cc
+++ b/tests/overlay_amplification.cc
@@ -56,7 +56,11 @@ void put_u16_be(std::vector<uint8_t>& out, uint16_t v) {
}
void append_fourcc(std::vector<uint8_t>& out, const char fourcc[4]) {
- out.insert(out.end(), fourcc, fourcc + 4);
+ // Append the bytes one at a time. A range insert from the char array makes
+ // GCC 13 report a bogus -Wstringop-overflow in optimized builds.
+ for (int i = 0; i < 4; i++) {
+ out.push_back(static_cast<uint8_t>(fourcc[i]));
+ }
}
void append(std::vector<uint8_t>& out, const std::vector<uint8_t>& v) {
diff --git a/tests/uncompressed_tile_range_overflow.cc b/tests/uncompressed_tile_range_overflow.cc
index a858bcc7..5042374a 100644
--- a/tests/uncompressed_tile_range_overflow.cc
+++ b/tests/uncompressed_tile_range_overflow.cc
@@ -70,7 +70,11 @@ void put_u16_be(std::vector<uint8_t>& out, uint16_t v) {
}
void append_fourcc(std::vector<uint8_t>& out, const char fourcc[4]) {
- out.insert(out.end(), fourcc, fourcc + 4);
+ // Append the bytes one at a time. A range insert from the char array makes
+ // GCC 13 report a bogus -Wstringop-overflow in optimized builds.
+ for (int i = 0; i < 4; i++) {
+ out.push_back(static_cast<uint8_t>(fourcc[i]));
+ }
}
void append_cstr(std::vector<uint8_t>& out, const char* s) {