Registry: typed refusals for every input failure; strict manifest reader; retire rerun converges
Empty, NUL and unreadable paths, malformed UTF-8 and lone surrogates refuse with the command's exit 1. The manifest is bounded (1 MiB, 1000 ships) and duplicate JSON properties are refused. Titles refuse format, line and paragraph separator characters and edge whitespace. Naming an already retired key is a recorded no-op, so a rerun converges. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
11df901cb6
commit
0bb3b2f76c
3 changed files with 419 additions and 23 deletions
|
|
@ -44,13 +44,25 @@ public static class ConceptCommand
|
|||
}
|
||||
}
|
||||
|
||||
private static async Task<string> ReadManifestAsync(string path)
|
||||
// Reads at most one byte past the bound, so a wrong file is never read whole.
|
||||
private static async Task<byte[]> ReadManifestAsync(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await File.ReadAllTextAsync(path);
|
||||
await using var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, 1, true);
|
||||
var buffer = new byte[ConceptSubjectRegistry.MaxManifestBytes + 1];
|
||||
var length = 0;
|
||||
int read;
|
||||
while (length < buffer.Length && (read = await stream.ReadAsync(buffer.AsMemory(length))) > 0)
|
||||
{
|
||||
length += read;
|
||||
}
|
||||
|
||||
return buffer[..length];
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
||||
// An empty or NUL path is an ArgumentException; a path the platform cannot name is NotSupported.
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or ArgumentException
|
||||
or NotSupportedException or System.Security.SecurityException)
|
||||
{
|
||||
throw new ManifestRefusedException("manifest", "Unreadable");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue