Abseil LTS branch, Jan 2025, Patch 2 (#2010)
* Fix sign-extension issue in absl::HexStringToBytes()
diff --git a/MODULE.bazel b/MODULE.bazel
index 5c8b337..c30e977 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -16,7 +16,7 @@
module(
name = "abseil-cpp",
- version = "20250127.1",
+ version = "20250127.2",
compatibility_level = 1,
)
diff --git a/absl/base/config.h b/absl/base/config.h
index 63b9642..ed74d67 100644
--- a/absl/base/config.h
+++ b/absl/base/config.h
@@ -118,7 +118,7 @@
// LTS releases can be obtained from
// https://github.com/abseil/abseil-cpp/releases.
#define ABSL_LTS_RELEASE_VERSION 20250127
-#define ABSL_LTS_RELEASE_PATCH_LEVEL 1
+#define ABSL_LTS_RELEASE_PATCH_LEVEL 2
// Helper macro to convert a CPP variable to a string literal.
#define ABSL_INTERNAL_DO_TOKEN_STR(x) #x
diff --git a/absl/strings/escaping.cc b/absl/strings/escaping.cc
index b70c504..8570d86 100644
--- a/absl/strings/escaping.cc
+++ b/absl/strings/escaping.cc
@@ -845,7 +845,7 @@
}
/* clang-format off */
-constexpr std::array<char, 256> kHexValueLenient = {
+constexpr std::array<uint8_t, 256> kHexValueLenient = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -864,7 +864,7 @@
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
-constexpr std::array<signed char, 256> kHexValueStrict = {
+constexpr std::array<int8_t, 256> kHexValueStrict = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
@@ -892,7 +892,7 @@
size_t num) {
for (size_t i = 0; i < num; i++) {
to[i] = static_cast<char>(kHexValueLenient[from[i * 2] & 0xFF] << 4) +
- (kHexValueLenient[from[i * 2 + 1] & 0xFF]);
+ static_cast<char>(kHexValueLenient[from[i * 2 + 1] & 0xFF]);
}
}
@@ -989,8 +989,10 @@
auto hex_p = hex.cbegin();
for (std::string::iterator bin_p = output.begin(); bin_p != output.end();
++bin_p) {
- int h1 = absl::kHexValueStrict[static_cast<size_t>(*hex_p++)];
- int h2 = absl::kHexValueStrict[static_cast<size_t>(*hex_p++)];
+ int h1 = absl::kHexValueStrict[static_cast<size_t>(
+ static_cast<uint8_t>(*hex_p++))];
+ int h2 = absl::kHexValueStrict[static_cast<size_t>(
+ static_cast<uint8_t>(*hex_p++))];
if (h1 == -1 || h2 == -1) {
output.resize(static_cast<size_t>(bin_p - output.begin()));
return false;
diff --git a/absl/strings/escaping_test.cc b/absl/strings/escaping_test.cc
index 25cb685..865f953 100644
--- a/absl/strings/escaping_test.cc
+++ b/absl/strings/escaping_test.cc
@@ -723,6 +723,10 @@
bytes = "abc";
EXPECT_TRUE(absl::HexStringToBytes("", &bytes));
EXPECT_EQ("", bytes); // Results in empty output.
+
+ // Ensure there is no sign extension bug on a signed char.
+ hex.assign("\xC8" "b", 2);
+ EXPECT_FALSE(absl::HexStringToBytes(hex, &bytes));
}
TEST(HexAndBack, HexStringToBytes_and_BytesToHexString) {