@samitouri / QOSAMI-WSL / commits / b1ec0b31

Fix relay bug causing image import to fail without a proper error (#40892)

* Fix relay bug causing image import to fail without a proper error * Apply PR suggestions Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Blue committed Jun 24, 2026 at 16:10 UTC b1ec0b31152e8a721bf493175fcd0b3976ff3d1b
2 files changed +31
src/linux/init/WSLCInit.cpp
+7
@@ -340,6 +340,13 @@ void HandleMessageImpl(
340 }
341 else if (UtilWriteBuffer(socket.get(), relayBuffer.data(), bytesRead) < 0)
342 {
343 + if (errno == ECONNRESET || errno == EPIPE)
344 + {
345 + // The other side of the socket has been closed. This isn't necessarily an error, so stop relaying this direction.
346 + pollDescriptors[1].fd = -1;
347 + continue;
348 + }
349 +
350 LOG_ERROR("write failed {}", errno);
351 break;
352 }
test/windows/WSLCTests.cpp
+24
@@ -1327,6 +1327,30 @@ class WSLCTests
1327 ValidateCOMErrorMessage(L"archive/tar: invalid tar header");
1328 }
1329
1330 + // Validate that a large (300MB) invalid tar fails with proper error message and code.
1331 + {
1332 + auto largeFile =
1333 + wil::create_new_file(L"largefile", GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, nullptr, FILE_FLAG_DELETE_ON_CLOSE);
1334 +
1335 + // Create an invalid header (docker ignores the entire file if its header is only null bytes).
1336 + DWORD bytesWritten{};
1337 + THROW_IF_WIN32_BOOL_FALSE(WriteFile(largeFile.get(), "foo", 3, &bytesWritten, nullptr));
1338 + THROW_LAST_ERROR_IF(SetFilePointer(largeFile.get(), static_cast<LONG>(300 * _1MB), nullptr, FILE_BEGIN) == INVALID_SET_FILE_POINTER);
1339 +
1340 + THROW_IF_WIN32_BOOL_FALSE(SetEndOfFile(largeFile.get()));
1341 + THROW_LAST_ERROR_IF(SetFilePointer(largeFile.get(), 0, nullptr, FILE_BEGIN) == INVALID_SET_FILE_POINTER);
1342 +
1343 + VERIFY_IS_TRUE(GetFileSizeEx(largeFile.get(), &fileSize));
1344 + VERIFY_ARE_EQUAL(fileSize.QuadPart, 300 * _1MB);
1345 +
1346 + VERIFY_ARE_EQUAL(
1347 + m_defaultSession->ImportImage(
1348 + ToCOMInputHandle(largeFile.get()), "invalid-large-image:test", nullptr, fileSize.QuadPart, nullptr, &imageId),
1349 + E_FAIL);
1350 +
1351 + ValidateCOMErrorMessage(L"archive/tar: invalid tar header");
1352 + }
1353 +
1354 // Validate that ImportImage fails when the input pipe is closed during reading.
1355 {
1356 wil::unique_handle pipeRead;