Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
miyabe committed Sep 28, 2022
1 parent 7375f96 commit 67a7bbe
Show file tree
Hide file tree
Showing 7 changed files with 228 additions and 60 deletions.
18 changes: 17 additions & 1 deletion EncFSy_gui/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions EncFSy_gui/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ private void mount_Click(object sender, EventArgs e)
{
args += " --alt-stream";
}
if (this.mountManagerCheckBox.Checked)
{
args += " --dokan-mount-manager";
}
if (this.reverseCheckBox.Checked)
{
args += " --reverse";
Expand Down Expand Up @@ -219,5 +223,10 @@ private void checkBox1_CheckedChanged(object sender, EventArgs e)
{

}

private void checkBox1_CheckedChanged_1(object sender, EventArgs e)
{

}
}
}
14 changes: 9 additions & 5 deletions EncFSy_lib/EncFSFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ namespace EncFS {
SetLastError(ERROR_FILE_CORRUPT);
return -1;
}
//printf("write %d %ld %d %d\n", fileSize, fileIv, off, len);
// wprintf(L"Write %s %ld %ld\n", FileName, off, len);

if (off > fileSize) {
// Expand file.
Expand Down Expand Up @@ -336,6 +336,9 @@ namespace EncFS {
return false;
}
size_t fileSize = encfs.toDecodedLength(encodedFileSize.QuadPart);
if (fileSize == length) {
return true;
}

return this->_setLength(FileName, fileSize, length);
}
Expand All @@ -359,7 +362,7 @@ namespace EncFS {
// 境界部分をデコード
size_t blockHeaderSize = encfs.getHeaderSize();
size_t blockDataSize = encfs.getBlockSize() - blockHeaderSize;
size_t shift = 0;
size_t shift;
size_t blockNum;
size_t blocksOffset;
LARGE_INTEGER distanceToMove;
Expand All @@ -368,7 +371,7 @@ namespace EncFS {
shift = length % blockDataSize;
blockNum = length / blockDataSize;
}
else if (length > fileSize) {
else {
// 拡大
shift = fileSize % blockDataSize;
blockNum = fileSize / blockDataSize;
Expand All @@ -378,6 +381,7 @@ namespace EncFS {
return false;
}
if (shift != 0) {
// 境界部分をデコード
blocksOffset = blockNum * encfs.getBlockSize();
if (encfs.isUniqueIV()) {
blocksOffset += EncFS::EncFSVolume::HEADER_SIZE;
Expand Down Expand Up @@ -407,8 +411,8 @@ namespace EncFS {
}
this->lastBlockNum = -1;

// 境界部分をエンコード
if (shift != 0) {
// 境界部分をエンコード
size_t blockDataLen = length - blockNum * blockDataSize;
if (blockDataLen > blockDataSize) {
blockDataLen = blockDataSize;
Expand Down Expand Up @@ -437,7 +441,7 @@ namespace EncFS {
blockNum = length / blockDataSize;
this->decodeBuffer.assign(shift, (char)0);
this->encodeBuffer.clear();
encfs.encodeBlock(fileIv, blockNum, this->decodeBuffer, this->encodeBuffer);
encfs.encodeBlock(fileIv, this->lastBlockNum = blockNum, this->decodeBuffer, this->encodeBuffer);
distanceToMove.QuadPart = -(int64_t)shift - (int64_t)blockHeaderSize;
if (!SetFilePointerEx(this->handle, distanceToMove, NULL, FILE_END)) {
return false;
Expand Down
17 changes: 8 additions & 9 deletions EncFSy_lib/EncFSVolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ R"(<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
}

// getPaddedDecFilename
int padBytesSize = 16;
int padLen = padBytesSize - (plainFileName.size() % padBytesSize);
size_t padBytesSize = 16;
size_t padLen = padBytesSize - (plainFileName.size() % padBytesSize);
if (padLen == 0) {
padLen = padBytesSize;
}
Expand All @@ -366,7 +366,7 @@ R"(<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

string paddedFileName(plainFileName);
char iv[2];
for (int i = 0; i < padLen; ++i) {
for (size_t i = 0; i < padLen; ++i) {
paddedFileName += (char)padLen;
}
if (this->chainedNameIV) {
Expand Down Expand Up @@ -450,7 +450,7 @@ R"(<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
}
}

int padLen = plainFileName[plainFileName.size() - 1];
size_t padLen = plainFileName[plainFileName.size() - 1];
for (size_t i = 0; i < padLen; ++i) {
if (plainFileName[plainFileName.size() - padLen + i] != padLen) {
throw EncFSInvalidBlockException();
Expand Down Expand Up @@ -603,7 +603,7 @@ R"(<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
// 暗号化
if (this->allowHoles && srcBlock.size() + headerSize == this->blockSize) {
bool zeroBlock = true;
for (int i = 0; i < srcBlock.size(); ++i) {
for (size_t i = 0; i < srcBlock.size(); ++i) {
if (srcBlock[i] != 0) {
zeroBlock = false;
break;
Expand All @@ -623,7 +623,7 @@ R"(<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
string mac;
mac.resize(this->blockMACBytes);
mac64(this->volumeHmac, this->hmacLock, (const byte*)srcBlock.data(), srcBlock.size(), &mac[0]);
for (int i = 0; i < this->blockMACBytes; i++) {
for (size_t i = 0; i < this->blockMACBytes; i++) {
block[i] = mac[7 - i];
}

Expand All @@ -641,7 +641,7 @@ R"(<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
// 復号
if (this->allowHoles && srcBlock.size() == this->blockSize) {
bool zeroBlock = true;
for (int i = 0; i < srcBlock.size(); ++i) {
for (size_t i = 0; i < srcBlock.size(); ++i) {
if (srcBlock[i] != 0) {
zeroBlock = false;
break;
Expand All @@ -667,7 +667,7 @@ R"(<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
string mac;
mac.resize(this->blockMACBytes);
mac64(this->volumeHmac, this->hmacLock, (const byte*)destBlock.data() + this->blockMACBytes, destBlock.size() - this->blockMACBytes, &mac[0]);
for (int i = 0; i < this->blockMACBytes; i++) {
for (size_t i = 0; i < this->blockMACBytes; i++) {
if (destBlock[i] != mac[7 - i]) {
valid = false;
break;
Expand All @@ -680,5 +680,4 @@ R"(<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
destBlock.assign(destBlock.data() + headerSize, destBlock.size() - headerSize);
}
}

}
Loading

0 comments on commit 67a7bbe

Please sign in to comment.