From 635dbb97004ad99787de812fa536ada60a8b7318 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sun, 9 Apr 2023 11:39:36 -0700 Subject: [PATCH] win32_apply: retry creating hard links --- src/win32_apply.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/win32_apply.c b/src/win32_apply.c index 7a6ac845..e493ecfe 100644 --- a/src/win32_apply.c +++ b/src/win32_apply.c @@ -3,7 +3,7 @@ */ /* - * Copyright (C) 2013-2021 Eric Biggers + * Copyright 2013-2023 Eric Biggers * * This file is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free @@ -1852,16 +1852,25 @@ create_link(HANDLE h, const struct wim_dentry *dentry, info->FileNameLength = ctx->pathbuf.Length; memcpy(info->FileName, ctx->pathbuf.Buffer, ctx->pathbuf.Length); info->FileName[info->FileNameLength / 2] = L'\0'; + /* + * Note: the null terminator isn't actually necessary, but if + * you don't add the extra character, you get + * STATUS_INFO_LENGTH_MISMATCH when FileNameLength is 2. + */ - /* Note: the null terminator isn't actually necessary, - * but if you don't add the extra character, you get - * STATUS_INFO_LENGTH_MISMATCH when FileNameLength - * happens to be 2 */ - - status = NtSetInformationFile(h, &ctx->iosb, info, bufsize, - FileLinkInformation); - if (NT_SUCCESS(status)) - return 0; + /* + * When fuzzing with wlfuzz.exe, creating a hard link sometimes + * fails with STATUS_ACCESS_DENIED. However, it eventually + * succeeds when re-attempted... + */ + int i = 0; + do { + status = NtSetInformationFile(h, &ctx->iosb, info, + bufsize, + FileLinkInformation); + if (NT_SUCCESS(status)) + return 0; + } while (++i < 32); winnt_error(status, L"Failed to create link \"%ls\"", current_path(ctx)); return WIMLIB_ERR_LINK; -- 2.43.0