Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ZipDecompressor windows 0x80 (file attribute normal) #15260

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ private ZipDecompressor() {
private static final int S_IFREG = 0100000;
private static final int S_IFLNK = 0120000;
private static final int EXECUTABLE_MASK = 0755;

// source: https://docs.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants
@VisibleForTesting
static final int WINDOWS_FILE_ATTRIBUTE_DIRECTORY = 0x10;
@VisibleForTesting
static final int WINDOWS_DIRECTORY = 0x10;
static final int WINDOWS_FILE_ATTRIBUTE_ARCHIVE = 0x20;
@VisibleForTesting
static final int WINDOWS_FILE = 0x20;
static final int WINDOWS_FILE_ATTRIBUTE_NORMAL = 0x80;

/**
* This unzips the zip file to directory {@link DecompressorDescriptor#repositoryPath()}, which by
Expand Down Expand Up @@ -186,10 +190,12 @@ static int getPermissions(int permissions, String path) throws IOException {
// https://github.com/miloyip/rapidjson/archive/v1.0.2.zip, it looks like executables end up
// with "normal" (posix) permissions (oddly), so they'll be handled above.
int windowsPermission = permissions & 0xff;
if ((windowsPermission & WINDOWS_DIRECTORY) == WINDOWS_DIRECTORY) {
if ((windowsPermission & WINDOWS_FILE_ATTRIBUTE_DIRECTORY) == WINDOWS_FILE_ATTRIBUTE_DIRECTORY) {
// Directory.
return S_IFDIR | EXECUTABLE_MASK;
} else if (permissions == 0 || (windowsPermission & WINDOWS_FILE) == WINDOWS_FILE) {
} else if (permissions == 0 ||
(windowsPermission & WINDOWS_FILE_ATTRIBUTE_ARCHIVE) == WINDOWS_FILE_ATTRIBUTE_ARCHIVE ||
(windowsPermission & WINDOWS_FILE_ATTRIBUTE_NORMAL) == WINDOWS_FILE_ATTRIBUTE_NORMAL) {
// File.
return S_IFREG | EXECUTABLE_MASK;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ public void testGetPermissions() throws Exception {

@Test
public void testWindowsPermissions() throws Exception {
int permissions = ZipDecompressor.getPermissions(ZipDecompressor.WINDOWS_DIRECTORY, "foo/bar");
int permissions = ZipDecompressor.getPermissions(ZipDecompressor.WINDOWS_FILE_ATTRIBUTE_DIRECTORY, "foo/bar");
assertThat(permissions).isEqualTo(DIRECTORY);
permissions = ZipDecompressor.getPermissions(ZipDecompressor.WINDOWS_FILE, "foo/bar");
permissions = ZipDecompressor.getPermissions(ZipDecompressor.WINDOWS_FILE_ATTRIBUTE_ARCHIVE, "foo/bar");
assertThat(permissions).isEqualTo(EXECUTABLE);
permissions = ZipDecompressor.getPermissions(ZipDecompressor.WINDOWS_FILE_ATTRIBUTE_NORMAL, "foo/bar");
assertThat(permissions).isEqualTo(EXECUTABLE);
}

Expand Down