Skip to content

Commit d7aaad8

Browse files
authored
Abseil LTS Branch, Jan 2024, Patch 2 (#1650)
* Prevent overflow in absl::CEscape() Strings larger than 1 GiB on a platform with a 32-bit size_t could potentially overflow size_t in `CEscapedLength()`, resulting in an undersized allocation. The resulting write in `CEscapeAndAppendInternal()` would then write beyond the bounds of the output buffer. A second overflow, where the calculated escaped length is added to the size of the string being appended to, is also fixed. In both cases the program will now abort prior to the overflow. Credit goes to Ronald Crane (Zippenhop LLC) for reporting this issue. PiperOrigin-RevId: 607019573 Change-Id: I97bf246cde96102a793d2db49446cccae08abf59 * Workaround for NVIDIA C++ compiler being unable to parse variadic expansions in range of range-based for loop Fixes: #1629 PiperOrigin-RevId: 611131201 Change-Id: I787731e00207b544ee16055e6e0d323a5094a433 * Fix OSX support with CocoaPods and Xcode 15 PiperOrigin-RevId: 615090942 Change-Id: I7cc20a0129dcfbbddedd9e6d816bb6234bff14b3 * PR #1643: add xcprivacy to all subspecs Imported from GitHub PR #1643 Addressing comments at #1604 Add a xcprivacy subspec and have all other subspecs depend on it (option 1) Didn't going with option 3 because there are several levels of subspecs in abseil podspec, it's difficult to track whether all of them directly or indirectly depends on abseil/base/config or ensure they will continue to depend on it. Example of generated podsped: https://gist.github.com/HannahShiSFB/15d8fb6aa637f2781b7be4218d080f11 Merge 4405cdf into 4539c54 Merging this change closes #1643 COPYBARA_INTEGRATE_REVIEW=#1643 from HannahShiSFB:privacy-manifests 4405cdf PiperOrigin-RevId: 616914674 Change-Id: If56d5a4f1a7cc6f9fac7a2d8e95b55d140e645fc
1 parent 2f9e432 commit d7aaad8

File tree

5 files changed

+47
-19
lines changed

5 files changed

+47
-19
lines changed

Diff for: MODULE.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

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

Diff for: absl/abseil.podspec.gen.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,14 @@
4444
'ALWAYS_SEARCH_USER_PATHS' => 'NO',
4545
}
4646
s.ios.deployment_target = '9.0'
47-
s.osx.deployment_target = '10.10'
47+
s.osx.deployment_target = '10.11'
4848
s.tvos.deployment_target = '9.0'
4949
s.watchos.deployment_target = '2.0'
50+
s.subspec 'xcprivacy' do |ss|
51+
ss.resource_bundles = {
52+
ss.module_name => 'PrivacyInfo.xcprivacy',
53+
}
54+
end
5055
"""
5156

5257
# Rule object representing the rule of Bazel BUILD.
@@ -191,6 +196,12 @@ def write_podspec_rule(f, rule, depth):
191196
name = get_spec_name(dep.replace(":", "/"))
192197
f.write("{indent}{var}.dependency '{dep}'\n".format(
193198
indent=indent, var=spec_var, dep=name))
199+
# Writes dependency to xcprivacy
200+
f.write(
201+
"{indent}{var}.dependency '{dep}'\n".format(
202+
indent=indent, var=spec_var, dep="abseil/xcprivacy"
203+
)
204+
)
194205

195206

196207
def write_indented_list(f, leading, values):

Diff for: absl/base/config.h

+1-1
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 20240116
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

Diff for: absl/strings/escaping.cc

+22-4
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ std::string CEscapeInternal(absl::string_view src, bool use_hex,
362362
}
363363

364364
/* clang-format off */
365-
constexpr unsigned char c_escaped_len[256] = {
365+
constexpr unsigned char kCEscapedLen[256] = {
366366
4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 4, 4, 2, 4, 4, // \t, \n, \r
367367
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
368368
1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, // ", '
@@ -387,8 +387,23 @@ constexpr unsigned char c_escaped_len[256] = {
387387
// that UTF-8 bytes are not handled specially.
388388
inline size_t CEscapedLength(absl::string_view src) {
389389
size_t escaped_len = 0;
390-
for (char c : src)
391-
escaped_len += c_escaped_len[static_cast<unsigned char>(c)];
390+
// The maximum value of kCEscapedLen[x] is 4, so we can escape any string of
391+
// length size_t_max/4 without checking for overflow.
392+
size_t unchecked_limit =
393+
std::min<size_t>(src.size(), std::numeric_limits<size_t>::max() / 4);
394+
size_t i = 0;
395+
while (i < unchecked_limit) {
396+
// Common case: No need to check for overflow.
397+
escaped_len += kCEscapedLen[static_cast<unsigned char>(src[i++])];
398+
}
399+
while (i < src.size()) {
400+
// Beyond unchecked_limit we need to check for overflow before adding.
401+
size_t char_len = kCEscapedLen[static_cast<unsigned char>(src[i++])];
402+
ABSL_INTERNAL_CHECK(
403+
escaped_len <= std::numeric_limits<size_t>::max() - char_len,
404+
"escaped_len overflow");
405+
escaped_len += char_len;
406+
}
392407
return escaped_len;
393408
}
394409

@@ -400,12 +415,15 @@ void CEscapeAndAppendInternal(absl::string_view src, std::string* dest) {
400415
}
401416

402417
size_t cur_dest_len = dest->size();
418+
ABSL_INTERNAL_CHECK(
419+
cur_dest_len <= std::numeric_limits<size_t>::max() - escaped_len,
420+
"std::string size overflow");
403421
strings_internal::STLStringResizeUninitialized(dest,
404422
cur_dest_len + escaped_len);
405423
char* append_ptr = &(*dest)[cur_dest_len];
406424

407425
for (char c : src) {
408-
size_t char_len = c_escaped_len[static_cast<unsigned char>(c)];
426+
size_t char_len = kCEscapedLen[static_cast<unsigned char>(c)];
409427
if (char_len == 1) {
410428
*append_ptr++ = c;
411429
} else if (char_len == 2) {

Diff for: absl/strings/str_cat.h

+11-12
Original file line numberDiff line numberDiff line change
@@ -601,18 +601,17 @@ StrAppend(absl::Nonnull<String*> str, T... args) {
601601
ptrdiff_t n; // The length of the current argument
602602
typename String::pointer pos = &(*str)[old_size];
603603
using SomeTrivialEmptyType = std::false_type;
604-
// Ugly code due to the lack of C++14 fold expression makes us.
605-
const SomeTrivialEmptyType dummy1;
606-
for (const SomeTrivialEmptyType& dummy2 :
607-
{(/* Comma expressions are poor man's C++17 fold expression for C++14 */
608-
(void)(n = lengths[i]),
609-
(void)(n < 0 ? (void)(*pos++ = '-'), (n = ~n) : 0),
610-
(void)absl::numbers_internal::FastIntToBufferBackward(
611-
absl::numbers_internal::UnsignedAbsoluteValue(std::move(args)),
612-
pos += n, static_cast<uint32_t>(n)),
613-
(void)++i, dummy1)...}) {
614-
(void)dummy2; // Remove & migrate to fold expressions in C++17
615-
}
604+
const SomeTrivialEmptyType dummy;
605+
// Ugly code due to the lack of C++17 fold expressions
606+
const SomeTrivialEmptyType dummies[] = {
607+
(/* Comma expressions are poor man's C++17 fold expression for C++14 */
608+
(void)(n = lengths[i]),
609+
(void)(n < 0 ? (void)(*pos++ = '-'), (n = ~n) : 0),
610+
(void)absl::numbers_internal::FastIntToBufferBackward(
611+
absl::numbers_internal::UnsignedAbsoluteValue(std::move(args)),
612+
pos += n, static_cast<uint32_t>(n)),
613+
(void)++i, dummy)...};
614+
(void)dummies; // Remove & migrate to fold expressions in C++17
616615
}
617616

618617
// Helper function for the future StrCat default floating-point format, %.6g

0 commit comments

Comments
 (0)