Skip to content

Commit 38bb0b9

Browse files
authored
Abseil LTS branch, May 2025, Patch 2 (#2009)
* Fix sign-extension issue in absl::HexStringToBytes()
1 parent 76bb243 commit 38bb0b9

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
module(
1818
name = "abseil-cpp",
19-
version = "20250512.1",
19+
version = "20250512.2",
2020
compatibility_level = 1,
2121
)
2222

absl/base/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
// LTS releases can be obtained from
119119
// https://github.com/abseil/abseil-cpp/releases.
120120
#define ABSL_LTS_RELEASE_VERSION 20250512
121-
#define ABSL_LTS_RELEASE_PATCH_LEVEL 1
121+
#define ABSL_LTS_RELEASE_PATCH_LEVEL 2
122122

123123
// Helper macro to convert a CPP variable to a string literal.
124124
#define ABSL_INTERNAL_DO_TOKEN_STR(x) #x

absl/strings/escaping.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ bool Base64UnescapeInternal(const char* absl_nullable src, size_t slen,
827827
}
828828

829829
/* clang-format off */
830-
constexpr std::array<char, 256> kHexValueLenient = {
830+
constexpr std::array<uint8_t, 256> kHexValueLenient = {
831831
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
832832
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
833833
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -846,7 +846,7 @@ constexpr std::array<char, 256> kHexValueLenient = {
846846
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
847847
};
848848

849-
constexpr std::array<signed char, 256> kHexValueStrict = {
849+
constexpr std::array<int8_t, 256> kHexValueStrict = {
850850
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
851851
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
852852
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
@@ -874,7 +874,7 @@ void HexStringToBytesInternal(const char* absl_nullable from, T to,
874874
size_t num) {
875875
for (size_t i = 0; i < num; i++) {
876876
to[i] = static_cast<char>(kHexValueLenient[from[i * 2] & 0xFF] << 4) +
877-
(kHexValueLenient[from[i * 2 + 1] & 0xFF]);
877+
static_cast<char>(kHexValueLenient[from[i * 2 + 1] & 0xFF]);
878878
}
879879
}
880880

@@ -970,8 +970,10 @@ bool HexStringToBytes(absl::string_view hex, std::string* absl_nonnull bytes) {
970970
auto hex_p = hex.cbegin();
971971
for (std::string::iterator bin_p = output.begin(); bin_p != output.end();
972972
++bin_p) {
973-
int h1 = absl::kHexValueStrict[static_cast<size_t>(*hex_p++)];
974-
int h2 = absl::kHexValueStrict[static_cast<size_t>(*hex_p++)];
973+
int h1 = absl::kHexValueStrict[static_cast<size_t>(
974+
static_cast<uint8_t>(*hex_p++))];
975+
int h2 = absl::kHexValueStrict[static_cast<size_t>(
976+
static_cast<uint8_t>(*hex_p++))];
975977
if (h1 == -1 || h2 == -1) {
976978
output.resize(static_cast<size_t>(bin_p - output.begin()));
977979
return false;

absl/strings/escaping_test.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,10 @@ TEST(Escaping, HexStringToBytesBackToHex) {
733733
bytes = "abc";
734734
EXPECT_TRUE(absl::HexStringToBytes("", &bytes));
735735
EXPECT_EQ("", bytes); // Results in empty output.
736+
737+
// Ensure there is no sign extension bug on a signed char.
738+
hex.assign("\xC8" "b", 2);
739+
EXPECT_FALSE(absl::HexStringToBytes(hex, &bytes));
736740
}
737741

738742
TEST(HexAndBack, HexStringToBytes_and_BytesToHexString) {

0 commit comments

Comments
 (0)