fix(asar): correct archive tree lookups and fail loudly on unreadable input

InsertFile resolved the grandparent node instead of the parent.
Reads no longer create phantom directories in the header.
Bound symlink traversal and skip reparse points when crawling.
Locked or unreadable files now abort packing instead of being dropped.
Read headers and integrity blocks with a full-read loop.
Assert the header keeps its size before overwriting the placeholder.
Validate Pickle buffer sizes, payload overflow and negative lengths.
Check CreateSymbolicLink and external tool exit codes.
Drop unused Pickle accessors, TransformedFile and FilesystemFilesAndLinks.Links.
This commit is contained in:
kitbyte
2026-08-29 16:55:55 +03:00
parent f798714f8d
commit 20956c3228
9 changed files with 163 additions and 245 deletions
+9 -8
View File
@@ -159,13 +159,6 @@ namespace AsarSharp
FilesystemEntry file, HashSet<string> dirCache)
{
var linkSrcPath = Extensions.GetDirectoryName(Path.Combine(dest, file.Link));
var linkDestPath = Extensions.GetDirectoryName(destFilename);
var relativeLinkPath = Extensions.GetRelativePath(linkDestPath, linkSrcPath);
try { File.Delete(destFilename); }
catch { /* ignore — failing to remove an existing link is non-fatal */ }
var linkTo = Path.Combine(relativeLinkPath, Path.GetFileName(file.Link));
if (!Extensions.IsPathInside(dest, linkSrcPath))
{
@@ -173,6 +166,12 @@ namespace AsarSharp
$"{fullPath}: file \"{file.Link}\" links out of the package to \"{linkSrcPath}\"");
}
try { File.Delete(destFilename); }
catch (Exception e) when (e is IOException || e is UnauthorizedAccessException)
{
// Nothing to replace, or the old entry is locked; the copy below reports the real failure.
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var targetPath = Path.Combine(linkSrcPath, Path.GetFileName(file.Link));
@@ -189,8 +188,10 @@ namespace AsarSharp
}
else
{
var linkDestPath = Extensions.GetDirectoryName(destFilename);
var relativeLinkPath = Extensions.GetRelativePath(linkDestPath, linkSrcPath);
EnsureParentDir(destFilename, dirCache);
Extensions.CreateSymbolicLink(linkTo, destFilename);
Extensions.CreateSymbolicLink(Path.Combine(relativeLinkPath, Path.GetFileName(file.Link)), destFilename);
}
}
}