Abseil LTS branch, July 2024, Patch 2 (#2011)
* Fix sign-extension issue in absl::HexStringToBytes()
diff --git a/MODULE.bazel b/MODULE.bazel
index 59ae492..c4c53c6 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -16,7 +16,7 @@
module(
name = "abseil-cpp",
- version = "20240722.1",
+ version = "20240722.2",
compatibility_level = 1,
)
diff --git a/absl/base/config.h b/absl/base/config.h
index 46e6fbc..6fc0a32 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 20240722
-#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 4ffef94..bc178fc 100644
--- a/absl/strings/escaping.cc
+++ b/absl/strings/escaping.cc
@@ -837,7 +837,7 @@
}
/* clang-format off */
-constexpr char kHexValueLenient[256] = {
+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,
@@ -856,7 +856,7 @@
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
-constexpr signed char kHexValueStrict[256] = {
+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,
@@ -884,7 +884,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]);
}
}
@@ -981,8 +981,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) {