Skip to content
Merged
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
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ tmp
*.user
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated but I keep getting annoyed that the test-storage directory isn't in the gitignore in the main branch.

*.csproj
*.vcxproj
*.targets
*.filters
*.pdb
*.lib
Expand Down Expand Up @@ -42,7 +41,6 @@ linux/init
initrd/init
bin/
*.nupkg
build/
generated/
*.nuspec
test/linux/unit_tests/wsl_unit_tests
Expand All @@ -65,4 +63,7 @@ package/x64
/appx-logs.txt
tools/clang-format.exe
/linux-crashes
doc/site/
doc/site/
directory.build.targets
test-storage/
*.vhdx
3 changes: 1 addition & 2 deletions msipackage/package.wix.in
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,7 @@
<!-- This needs to run after the registry is written because this action needs to read the install path -->
<Custom Action="RegisterLspCategories" After="WriteRegistryValues" Condition='((not REMOVE~="ALL") or WIX_UPGRADE_DETECTED) and (not UPGRADINGPRODUCTCODE) and (not SKIPLSP = 1)' />

<!-- Generate initrd.img from the init binary during installation.
Only run when the tools component is being installed ($tools=3), not during same-version reinstalls -->
<!-- Generate initrd.img from the init binary whenever the tools component is being installed -->
<Custom Action="CreateInitrd" After="RegisterLspCategories" Condition='$tools=3' />

<!-- This needs to run before the registry is cleared because this action needs to read the install path.
Expand Down
8 changes: 5 additions & 3 deletions src/windows/common/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,7 @@ void wsl::windows::common::filesystem::CreateCpioInitrd(_In_ const std::filesyst
constexpr size_t headerSize = 110;
const auto nameLen = strlen(name) + 1;
const auto headerPadding = (4 - ((headerSize + nameLen) % 4)) % 4;
const bool isTrailer = strcmp(name, "TRAILER!!!") == 0;

// Get current time for mtime. CPIO newc format only supports 32-bit fields.
const auto mtime = static_cast<DWORD>(time(nullptr));
Expand All @@ -1165,10 +1166,10 @@ void wsl::windows::common::filesystem::CreateCpioInitrd(_In_ const std::filesyst
"%08X" // namesize
"%08X", // check
0,
(fileSize > 0) ? 0100755 : 0,
isTrailer ? 0 : 0100755,
0,
0,
(fileSize > 0) ? 1 : 0,
isTrailer ? 0 : 1,
Comment on lines 1168 to +1172
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the CPIO header fields so that empty files (fileSize==0) still get a regular-file mode/nlink, and only the trailer gets zeros. The existing CreateCpioInitrd test parses filesize/namesize but doesn’t assert mode/nlink, so it wouldn’t catch regressions in this logic. Consider extending the test to parse and validate mode/nlink at least for sourceSize=0 (and ideally also validate the trailer entry).

Copilot uses AI. Check for mistakes.
mtime,
fileSize,
0,
Expand Down Expand Up @@ -1214,7 +1215,8 @@ void wsl::windows::common::filesystem::CreateCpioInitrd(_In_ const std::filesyst
LARGE_INTEGER currentPos{};
THROW_IF_WIN32_BOOL_FALSE(SetFilePointerEx(destFile.get(), {}, &currentPos, FILE_CURRENT));

const auto archivePadding = (archiveBlockSize - (currentPos.LowPart % archiveBlockSize)) % archiveBlockSize;
const auto currentSize = static_cast<ULONGLONG>(currentPos.QuadPart);
const auto archivePadding = static_cast<DWORD>((archiveBlockSize - (currentSize % archiveBlockSize)) % archiveBlockSize);
if (archivePadding > 0)
{
char paddingBuffer[archiveBlockSize] = {0};
Expand Down
6 changes: 3 additions & 3 deletions test/windows/SimpleTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,10 @@ class SimpleTests
THROW_IF_WIN32_BOOL_FALSE(GetFileSizeEx(cpioHandle.get(), &cpioSize));
VERIFY_ARE_EQUAL(cpioSize.QuadPart % 512, 0LL); // Archive padded to 512-byte boundary

char header[110] = {};
char header[111] = {};
DWORD bytesRead;
THROW_IF_WIN32_BOOL_FALSE(ReadFile(cpioHandle.get(), header, sizeof(header), &bytesRead, nullptr));
VERIFY_ARE_EQUAL(bytesRead, static_cast<DWORD>(sizeof(header)));
THROW_IF_WIN32_BOOL_FALSE(ReadFile(cpioHandle.get(), header, 110, &bytesRead, nullptr));
VERIFY_ARE_EQUAL(bytesRead, 110u);
Comment on lines +330 to +331
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The header size is hard-coded as 110 in both the ReadFile length and the VERIFY_ARE_EQUAL check. Since the buffer size was just changed to 111 to include a null terminator, consider using a single named constant (or sizeof(header) - 1) to keep the read length/check consistent and avoid future off-by-one drift.

Suggested change
THROW_IF_WIN32_BOOL_FALSE(ReadFile(cpioHandle.get(), header, 110, &bytesRead, nullptr));
VERIFY_ARE_EQUAL(bytesRead, 110u);
const DWORD headerBytesToRead = static_cast<DWORD>(sizeof(header) - 1);
THROW_IF_WIN32_BOOL_FALSE(ReadFile(cpioHandle.get(), header, headerBytesToRead, &bytesRead, nullptr));
VERIFY_ARE_EQUAL(bytesRead, headerBytesToRead);

Copilot uses AI. Check for mistakes.

// Parse CPIO newc header: magic(6) ino mode uid gid nlink mtime filesize devmajor devminor rdevmajor rdevminor namesize check
DWORD fileSize, nameSize;
Expand Down
Loading