From 875640558c3d4efc0a2c45a31be3c7fa8172ec55 Mon Sep 17 00:00:00 2001 From: Apple Date: Fri, 20 Jul 2018 18:11:38 +0000 Subject: [PATCH] copyfile-146.200.3.tar.gz --- copyfile.c | 56 +++++++++++++++++++++--------- copyfile.xcodeproj/project.pbxproj | 5 ++- xattr_flags.c | 2 ++ xcodescripts/copyfile.xcconfig | 2 ++ 4 files changed, 48 insertions(+), 17 deletions(-) diff --git a/copyfile.c b/copyfile.c index f07b86d..885bd4d 100644 --- a/copyfile.c +++ b/copyfile.c @@ -79,6 +79,8 @@ static int qtn_file_set_flags(void *x, uint32_t flags) { return 0; } #include "copyfile_private.h" #include "xattr_flags.h" +#define XATTR_ROOT_INSTALLED_NAME "com.apple.root.installed" + enum cfInternalFlags { cfDelayAce = 1 << 0, /* set if ACE shouldn't be set until post-order traversal */ cfMakeFileInvisible = 1 << 1, /* set if kFinderInvisibleMask is on src */ @@ -2330,7 +2332,7 @@ static int copyfile_data(copyfile_state_t s) int ret = 0; size_t iBlocksize = 0, iMinblocksize = 0; size_t oBlocksize = 0, oMinblocksize = 0; // If 0, we don't support sparse copying. - const size_t onegig = 1 << 30; + const size_t blocksize_limit = 1 << 30; // 1 GiB struct statfs sfs; copyfile_callback_t status = s->statuscb; @@ -2350,6 +2352,8 @@ static int copyfile_data(copyfile_state_t s) } #endif + // Calculate the input and output block sizes. + // Our output block size can be no greater than our input block size. if (fstatfs(s->src_fd, &sfs) == -1) { iBlocksize = s->sb.st_blksize; } else { @@ -2357,23 +2361,27 @@ static int copyfile_data(copyfile_state_t s) iMinblocksize = sfs.f_bsize; } - /* Work-around for 6453525, limit blocksize to 1G */ - if (iBlocksize > onegig) { - iBlocksize = onegig; - } - if (fstatfs(s->dst_fd, &sfs) == -1) { oBlocksize = iBlocksize; - } else if (sfs.f_iosize == 0) { - oBlocksize = iBlocksize; - oMinblocksize = sfs.f_bsize; } else { + oBlocksize = (sfs.f_iosize == 0) ? iBlocksize : MIN((size_t) sfs.f_iosize, iBlocksize); oMinblocksize = sfs.f_bsize; - oBlocksize = sfs.f_iosize; - if (oBlocksize > onegig) - oBlocksize = onegig; } + // 6453525 and 34848916 require us to limit our blocksize to resonable values. + if ((size_t) s->sb.st_size < iBlocksize && iMinblocksize > 0) { + copyfile_debug(3, "rounding up block size from fsize: %lld to multiple of %zu\n", s->sb.st_size, iMinblocksize); + iBlocksize = roundup((size_t) s->sb.st_size, iMinblocksize); + oBlocksize = MIN(oBlocksize, iBlocksize); + } + + if (iBlocksize > blocksize_limit) { + iBlocksize = blocksize_limit; + oBlocksize = MIN(oBlocksize, iBlocksize); + } + + copyfile_debug(3, "input block size: %zu output block size: %zu\n", iBlocksize, oBlocksize); + s->totalCopied = 0; // If requested, attempt a sparse copy. @@ -2958,9 +2966,16 @@ static int copyfile_xattr(copyfile_state_t s) } if (fsetxattr(s->dst_fd, name, xa_dataptr, xa_size, 0, look_for_decmpea) < 0) { - if (s->statuscb) + int error = errno; + if (error == EPERM && strcmp(name, XATTR_ROOT_INSTALLED_NAME) == 0) { + //Silently ignore if we fail to set XATTR_ROOT_INSTALLED_NAME + errno = error; + continue; + } + else if (s->statuscb) { int rv; + error = errno; if (s->xattr_name == NULL) s->xattr_name = strdup(name); rv = (*s->statuscb)(COPYFILE_COPY_XATTR, COPYFILE_ERR, s, s->src, s->dst, s->ctx); @@ -2973,8 +2988,9 @@ static int copyfile_xattr(copyfile_state_t s) } else { + errno = error; ret = -1; - copyfile_warn("could not set attributes %s on destination file descriptor: %s", name, strerror(errno)); + copyfile_warn("could not set attributes %s on destination file descriptor: %s", name, strerror(error)); continue; } } @@ -3918,9 +3934,14 @@ static int copyfile_unpack(copyfile_state_t s) goto exit; } } - if (fsetxattr(s->dst_fd, (char *)entry->name, dataptr, entry->length, 0, 0) == -1) { + //Silently ignore failure to set XATTR_ROOT_INSTALLED_NAME + int result = fsetxattr(s->dst_fd, (char *)entry->name, dataptr, entry->length, 0, 0); + int errorcode = errno; + if (result == -1 && !(errorcode == EPERM && + strcmp((char*)entry->name, XATTR_ROOT_INSTALLED_NAME) == 0)) { + errno = errorcode; if (COPYFILE_VERBOSE & s->flags) - copyfile_warn("error %d setting attribute %s", errno, entry->name); + copyfile_warn("error %d setting attribute %s", errorcode, entry->name); if (s->statuscb) { int rv; @@ -3940,6 +3961,7 @@ static int copyfile_unpack(copyfile_state_t s) } } else if (s->statuscb) { int rv; + errno = errorcode; s->xattr_name = strdup((char*)entry->name); s->totalCopied = entry->length; rv = (*s->statuscb)(COPYFILE_COPY_XATTR, COPYFILE_FINISH, s, s->src, s->dst, s->ctx); @@ -3952,6 +3974,8 @@ static int copyfile_unpack(copyfile_state_t s) s->err = ECANCELED; goto exit; } + } else { + errno = errorcode; } } } diff --git a/copyfile.xcodeproj/project.pbxproj b/copyfile.xcodeproj/project.pbxproj index 37eb53f..b8ec504 100644 --- a/copyfile.xcodeproj/project.pbxproj +++ b/copyfile.xcodeproj/project.pbxproj @@ -286,10 +286,11 @@ "$(inherited)", "$(SDKROOT)/usr/lib/system", ); - MACOSX_DEPLOYMENT_TARGET = 10.13; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; + SUPPORTS_TEXT_BASED_API = YES; + TAPI_VERIFY_MODE = Pedantic; }; name = Release; }; @@ -358,6 +359,8 @@ ); SDKROOT = macosx.internal; "SIM_SUFFIX[sdk=iphonesimulator*]" = _sim; + SUPPORTS_TEXT_BASED_API = YES; + TAPI_VERIFY_MODE = Pedantic; WARNING_CFLAGS = ( "-Wall", "-Wextra", diff --git a/xattr_flags.c b/xattr_flags.c index 8e8fd05..7144a4d 100644 --- a/xattr_flags.c +++ b/xattr_flags.c @@ -58,6 +58,7 @@ defaultUnboxedPropertyTable[] = { { "com.apple.security.", "S", propFlagsPrefix }, { XATTR_RESOURCEFORK_NAME, "PCS", 0 }, // Don't keep for safe save { XATTR_FINDERINFO_NAME, "PCS", 0 }, // Same as ResourceFork + { "com.apple.root.installed", "PC", 0}, // Don't share or sync. Copyable by entitled callers { 0, 0, 0 }, }; @@ -69,6 +70,7 @@ defaultSandboxedPropertyTable[] = { { "com.apple.security.", "N", propFlagsPrefix }, { XATTR_RESOURCEFORK_NAME, "PCS", 0 }, // Don't keep for safe save { XATTR_FINDERINFO_NAME, "PCS", 0 }, // Same as ResourceFork + { "com.apple.root.installed", "PC", 0}, // Don't share or sync. Copyable by entitled callers { 0, 0, 0 }, }; diff --git a/xcodescripts/copyfile.xcconfig b/xcodescripts/copyfile.xcconfig index d365fb5..c1aedf4 100644 --- a/xcodescripts/copyfile.xcconfig +++ b/xcodescripts/copyfile.xcconfig @@ -6,5 +6,7 @@ PUBLIC_HEADERS_FOLDER_PATH = /usr/include PRIVATE_HEADERS_FOLDER_PATH = /usr/local/include BUILD_VARIANTS = normal debug +VERSION_INFO_PREFIX = __attribute__((visibility("hidden"))) +IS_ZIPPERED = YES PRODUCT_NAME = copyfile -- 2.47.2