Skip to content

Commit 3cb205c

Browse files
authored
Abseil LTS branch, Jan 2025, Patch 2 (#2010)
* Fix sign-extension issue in absl::HexStringToBytes()
1 parent d9e4955 commit 3cb205c

4 files changed

Lines changed: 13 additions & 7 deletions

File tree

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 = "20250127.1",
19+
version = "20250127.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 20250127
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
@@ -845,7 +845,7 @@ bool Base64UnescapeInternal(absl::Nullable<const char*> src, size_t slen,
845845
}
846846

847847
/* clang-format off */
848-
constexpr std::array<char, 256> kHexValueLenient = {
848+
constexpr std::array<uint8_t, 256> kHexValueLenient = {
849849
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
850850
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
851851
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -864,7 +864,7 @@ constexpr std::array<char, 256> kHexValueLenient = {
864864
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
865865
};
866866

867-
constexpr std::array<signed char, 256> kHexValueStrict = {
867+
constexpr std::array<int8_t, 256> kHexValueStrict = {
868868
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
869869
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
870870
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
@@ -892,7 +892,7 @@ void HexStringToBytesInternal(absl::Nullable<const char*> from, T to,
892892
size_t num) {
893893
for (size_t i = 0; i < num; i++) {
894894
to[i] = static_cast<char>(kHexValueLenient[from[i * 2] & 0xFF] << 4) +
895-
(kHexValueLenient[from[i * 2 + 1] & 0xFF]);
895+
static_cast<char>(kHexValueLenient[from[i * 2 + 1] & 0xFF]);
896896
}
897897
}
898898

@@ -989,8 +989,10 @@ bool HexStringToBytes(absl::string_view hex,
989989
auto hex_p = hex.cbegin();
990990
for (std::string::iterator bin_p = output.begin(); bin_p != output.end();
991991
++bin_p) {
992-
int h1 = absl::kHexValueStrict[static_cast<size_t>(*hex_p++)];
993-
int h2 = absl::kHexValueStrict[static_cast<size_t>(*hex_p++)];
992+
int h1 = absl::kHexValueStrict[static_cast<size_t>(
993+
static_cast<uint8_t>(*hex_p++))];
994+
int h2 = absl::kHexValueStrict[static_cast<size_t>(
995+
static_cast<uint8_t>(*hex_p++))];
994996
if (h1 == -1 || h2 == -1) {
995997
output.resize(static_cast<size_t>(bin_p - output.begin()));
996998
return false;

absl/strings/escaping_test.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,10 @@ TEST(Escaping, HexStringToBytesBackToHex) {
723723
bytes = "abc";
724724
EXPECT_TRUE(absl::HexStringToBytes("", &bytes));
725725
EXPECT_EQ("", bytes); // Results in empty output.
726+
727+
// Ensure there is no sign extension bug on a signed char.
728+
hex.assign("\xC8" "b", 2);
729+
EXPECT_FALSE(absl::HexStringToBytes(hex, &bytes));
726730
}
727731

728732
TEST(HexAndBack, HexStringToBytes_and_BytesToHexString) {

0 commit comments

Comments
 (0)