Skip to content

Commit

Permalink
Merge pull request #15802 from protocolbuffers/cp-25.x
Browse files Browse the repository at this point in the history
Cherrypick Apple Privacy Manifest changes to make these available in 25.x
  • Loading branch information
zhangskz authored Feb 13, 2024
2 parents 971fbf6 + 17ec19d commit 70e459f
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ jobs:
vsversion: '2019'
cache-prefix: windows-2019-cmake
# windows-2019 has python3.7 installed, which is incompatible with the latest gcloud
python-version: '3.8'
python-version: '3.9'
- name: Windows CMake 32-bit
os: windows-2022
flags: >-
Expand Down
14 changes: 14 additions & 0 deletions PrivacyInfo.xcprivacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrivacyTracking</key>
<false/>
<key>NSPrivacyTrackingDomains</key>
<array/>
<key>NSPrivacyCollectedDataTypes</key>
<array/>
<key>NSPrivacyAccessedAPITypes</key>
<array/>
</dict>
</plist>
9 changes: 8 additions & 1 deletion Protobuf-C++.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ Pod::Spec.new do |s|
s.homepage = 'https://github.com/google/protobuf'
s.license = 'BSD-3-Clause'
s.authors = { 'The Protocol Buffers contributors' => 'protobuf@googlegroups.com' }
s.cocoapods_version = '>= 1.0'

# Ensure developers won't hit CocoaPods/CocoaPods#11402 with the resource
# bundle for the privacy manifest.
s.cocoapods_version = '>= 1.12.0'

s.source = { :git => 'https://github.com/google/protobuf.git',
:tag => "v#{s.version}" }
Expand All @@ -23,6 +26,10 @@ Pod::Spec.new do |s|
'src/google/protobuf/map_test_util*.{h,cc,inc}',
'src/google/protobuf/reflection_tester.{h,cc}'

s.resource_bundle = {
"Protobuf-C++_Privacy" => "PrivacyInfo.xcprivacy"
}

s.header_mappings_dir = 'src'

s.ios.deployment_target = '12.0'
Expand Down
9 changes: 8 additions & 1 deletion Protobuf.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ Pod::Spec.new do |s|
s.homepage = 'https://github.com/protocolbuffers/protobuf'
s.license = 'BSD-3-Clause'
s.authors = { 'The Protocol Buffers contributors' => 'protobuf@googlegroups.com' }
s.cocoapods_version = '>= 1.0'

# Ensure developers won't hit CocoaPods/CocoaPods#11402 with the resource
# bundle for the privacy manifest.
s.cocoapods_version = '>= 1.12.0'

s.source = { :git => 'https://github.com/protocolbuffers/protobuf.git',
:tag => "v#{s.version}" }
Expand All @@ -30,6 +33,10 @@ Pod::Spec.new do |s|
# left out, as it's an umbrella implementation file.
s.exclude_files = 'objectivec/GPBProtocolBuffers.m'

s.resource_bundle = {
"Protobuf_Privacy" => "PrivacyInfo.xcprivacy"
}

# Set a CPP symbol so the code knows to use framework imports.
s.user_target_xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1' }
s.pod_target_xcconfig = { 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1' }
Expand Down
18 changes: 12 additions & 6 deletions objectivec/GPBCodedInputStream.m
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) {
if (size == 0) {
result = @"";
} else {
CheckSize(state, size);
size_t size2 = (size_t)size; // Cast safe on 32bit because of CheckFieldSize() above.
CheckSize(state, size2);
result = [[NSString alloc] initWithBytes:&state->bytes[state->bufferPos]
length:ns_size
encoding:NSUTF8StringEncoding];
Expand All @@ -239,8 +240,9 @@ int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) {
NSData *GPBCodedInputStreamReadRetainedBytes(GPBCodedInputStreamState *state) {
uint64_t size = GPBCodedInputStreamReadUInt64(state);
CheckFieldSize(size);
size_t size2 = (size_t)size; // Cast safe on 32bit because of CheckFieldSize() above.
CheckSize(state, size2);
NSUInteger ns_size = (NSUInteger)size;
CheckSize(state, size);
NSData *result = [[NSData alloc] initWithBytes:state->bytes + state->bufferPos length:ns_size];
state->bufferPos += size;
return result;
Expand All @@ -249,8 +251,9 @@ int32_t GPBCodedInputStreamReadTag(GPBCodedInputStreamState *state) {
NSData *GPBCodedInputStreamReadRetainedBytesNoCopy(GPBCodedInputStreamState *state) {
uint64_t size = GPBCodedInputStreamReadUInt64(state);
CheckFieldSize(size);
size_t size2 = (size_t)size; // Cast safe on 32bit because of CheckFieldSize() above.
CheckSize(state, size2);
NSUInteger ns_size = (NSUInteger)size;
CheckSize(state, size);
// Cast is safe because freeWhenDone is NO.
NSData *result = [[NSData alloc] initWithBytesNoCopy:(void *)(state->bytes + state->bufferPos)
length:ns_size
Expand Down Expand Up @@ -338,7 +341,8 @@ - (BOOL)skipField:(int32_t)tag {
case GPBWireFormatLengthDelimited: {
uint64_t size = GPBCodedInputStreamReadUInt64(&state_);
CheckFieldSize(size);
SkipRawData(&state_, size);
size_t size2 = (size_t)size; // Cast safe on 32bit because of CheckFieldSize() above.
SkipRawData(&state_, size2);
return YES;
}
case GPBWireFormatStartGroup:
Expand Down Expand Up @@ -441,7 +445,8 @@ - (void)readMessage:(GPBMessage *)message
CheckRecursionLimit(&state_);
uint64_t length = GPBCodedInputStreamReadUInt64(&state_);
CheckFieldSize(length);
size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length);
size_t length2 = (size_t)length; // Cast safe on 32bit because of CheckFieldSize() above.
size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length2);
++state_.recursionDepth;
[message mergeFromCodedInputStream:self extensionRegistry:extensionRegistry];
GPBCodedInputStreamCheckLastTagWas(&state_, 0);
Expand All @@ -456,7 +461,8 @@ - (void)readMapEntry:(id)mapDictionary
CheckRecursionLimit(&state_);
uint64_t length = GPBCodedInputStreamReadUInt64(&state_);
CheckFieldSize(length);
size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length);
size_t length2 = (size_t)length; // Cast safe on 32bit because of CheckFieldSize() above.
size_t oldLimit = GPBCodedInputStreamPushLimit(&state_, length2);
++state_.recursionDepth;
GPBDictionaryReadEntry(mapDictionary, self, extensionRegistry, field, parentMessage);
GPBCodedInputStreamCheckLastTagWas(&state_, 0);
Expand Down
4 changes: 2 additions & 2 deletions src/google/protobuf/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <utility>

#if !defined(GOOGLE_PROTOBUF_NO_RDTSC) && defined(__APPLE__)
#include <mach/mach_time.h>
#include <time.h>
#endif

#include "google/protobuf/stubs/common.h"
Expand Down Expand Up @@ -691,7 +691,7 @@ class PROTOBUF_EXPORT UntypedMapBase {
#if defined(__APPLE__)
// Use a commpage-based fast time function on Apple environments (MacOS,
// iOS, tvOS, watchOS, etc).
s += mach_absolute_time();
s = clock_gettime_nsec_np(CLOCK_UPTIME_RAW);
#elif defined(__x86_64__) && defined(__GNUC__)
uint32_t hi, lo;
asm volatile("rdtsc" : "=a"(lo), "=d"(hi));
Expand Down

0 comments on commit 70e459f

Please sign in to comment.