Skip to content

Commit 216a6be

Browse files
authored
Abseil LTS branch, July 2024, Patch 2 (#2011)
* Fix sign-extension issue in absl::HexStringToBytes()
1 parent dd4c89b commit 216a6be

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 = "20240722.1",
19+
version = "20240722.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 20240722
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
@@ -837,7 +837,7 @@ bool Base64UnescapeInternal(absl::Nullable<const char*> src, size_t slen,
837837
}
838838

839839
/* clang-format off */
840-
constexpr char kHexValueLenient[256] = {
840+
constexpr std::array<uint8_t, 256> kHexValueLenient = {
841841
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
842842
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
843843
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -856,7 +856,7 @@ constexpr char kHexValueLenient[256] = {
856856
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
857857
};
858858

859-
constexpr signed char kHexValueStrict[256] = {
859+
constexpr std::array<int8_t, 256> kHexValueStrict = {
860860
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
861861
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
862862
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
@@ -884,7 +884,7 @@ void HexStringToBytesInternal(absl::Nullable<const char*> from, T to,
884884
size_t num) {
885885
for (size_t i = 0; i < num; i++) {
886886
to[i] = static_cast<char>(kHexValueLenient[from[i * 2] & 0xFF] << 4) +
887-
(kHexValueLenient[from[i * 2 + 1] & 0xFF]);
887+
static_cast<char>(kHexValueLenient[from[i * 2 + 1] & 0xFF]);
888888
}
889889
}
890890

@@ -981,8 +981,10 @@ bool HexStringToBytes(absl::string_view hex,
981981
auto hex_p = hex.cbegin();
982982
for (std::string::iterator bin_p = output.begin(); bin_p != output.end();
983983
++bin_p) {
984-
int h1 = absl::kHexValueStrict[static_cast<size_t>(*hex_p++)];
985-
int h2 = absl::kHexValueStrict[static_cast<size_t>(*hex_p++)];
984+
int h1 = absl::kHexValueStrict[static_cast<size_t>(
985+
static_cast<uint8_t>(*hex_p++))];
986+
int h2 = absl::kHexValueStrict[static_cast<size_t>(
987+
static_cast<uint8_t>(*hex_p++))];
986988
if (h1 == -1 || h2 == -1) {
987989
output.resize(static_cast<size_t>(bin_p - output.begin()));
988990
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)