Skip to content

Commit

Permalink
FILE_APPEND_DATA bug
Browse files Browse the repository at this point in the history
  • Loading branch information
miyabe committed Sep 25, 2022
1 parent 78b612a commit 7375f96
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 10 deletions.
3 changes: 1 addition & 2 deletions EncFSy_lib/EncFSFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ namespace EncFS {
}
string fileHeader;
fileHeader.resize(EncFSVolume::HEADER_SIZE);

DWORD ReadLength;
if (!ReadFile(this->handle, &fileHeader[0], (DWORD)fileHeader.size(), (LPDWORD)&ReadLength, NULL)) {
return false;
Expand Down Expand Up @@ -152,7 +151,7 @@ namespace EncFS {
SetLastError(ERROR_FILE_CORRUPT);
return -1;
}
//printf("write %d %d %d %d\n", fileSize, fileIv, off, len);
//printf("write %d %ld %d %d\n", fileSize, fileIv, off, len);

if (off > fileSize) {
// Expand file.
Expand Down
14 changes: 7 additions & 7 deletions EncFSy_lib/EncFSy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,17 +449,17 @@ EncFSCreateFile(LPCWSTR FileName, PDOKAN_IO_SECURITY_CONTEXT SecurityContext,
}
}

// Read access is required to read file header
if (genericDesiredAccess & GENERIC_WRITE) {
genericDesiredAccess |= GENERIC_READ;
// Read/write access are required to modify file header
if (genericDesiredAccess & GENERIC_WRITE
|| genericDesiredAccess & FILE_WRITE_DATA
|| genericDesiredAccess & FILE_APPEND_DATA) {
genericDesiredAccess |= FILE_READ_DATA | FILE_WRITE_DATA;
if (ShareAccess & FILE_SHARE_WRITE) {
ShareAccess |= FILE_SHARE_READ;
}
}

// Read/write access are required to modify file header
if (genericDesiredAccess & DELETE) {
genericDesiredAccess |= GENERIC_READ | GENERIC_WRITE;
genericDesiredAccess |= FILE_READ_DATA | FILE_WRITE_DATA;
if (ShareAccess & FILE_SHARE_DELETE) {
ShareAccess |= FILE_SHARE_WRITE | FILE_SHARE_READ;
}
Expand All @@ -470,7 +470,7 @@ EncFSCreateFile(LPCWSTR FileName, PDOKAN_IO_SECURITY_CONTEXT SecurityContext,
fileAttributesAndFlags = FILE_ATTRIBUTE_NORMAL;
}

// Cannot suppot no buffering mode (Encrypted files cannot align on the secter size)
// Cannot suppot no buffering mode (Encrypted files cannot align on the sector size)
if (fileAttributesAndFlags & FILE_FLAG_NO_BUFFERING) {
fileAttributesAndFlags ^= FILE_FLAG_NO_BUFFERING;
}
Expand Down
34 changes: 34 additions & 0 deletions EncFSy_test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,40 @@ int main()
CloseHandle(h);
}

// file append
{
DWORD dwDesiredAccess = FILE_APPEND_DATA;
DWORD dwShareMode = FILE_SHARE_WRITE;
DWORD dwCreationDisposition = CREATE_ALWAYS;
DWORD dwFlagsAndAttribute = FILE_ATTRIBUTE_NORMAL;
HANDLE h = CreateFileW(file, dwDesiredAccess, dwShareMode, NULL,
dwCreationDisposition, dwFlagsAndAttribute, NULL);
if (h == INVALID_HANDLE_VALUE) {
DWORD lastError = GetLastError();
printf("CreateFileW ERROR: %d\n", lastError);
return -1;
}

LARGE_INTEGER distanceToMove;
distanceToMove.QuadPart = 0;
if (!SetFilePointerEx(h, distanceToMove, NULL, FILE_BEGIN)) {
DWORD lastError = GetLastError();
printf("SetFilePointerEx ERROR: %d\n", lastError);
return -1;
}

const char* writeData = "ABCDEFG";
const DWORD size = sizeof(writeData);
DWORD readLen;
if (!WriteFile(h, writeData, size, &readLen, NULL)) {
DWORD lastError = GetLastError();
printf("WriteFile ERROR: %d\n", lastError);
return -1;
}

CloseHandle(h);
}

// no buffering mode
{
DWORD dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
Expand Down
2 changes: 1 addition & 1 deletion installer/installer.nsi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
!define VERSION "0.15"
!define VERSION "0.16"

!include LogicLib.nsh
!include x64.nsh
Expand Down

0 comments on commit 7375f96

Please sign in to comment.