Importazione e dati: «Tieni il più grande» per gruppi, righe di _febe.jsonl mai perse, ricostruzione robusta (import-1, import-2, library-1, journal-1, rebuild-1, rebuild-2, rebuild-3, backup-1)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
13 files changed
+1145
-95
No files matched your search
@@ -25,6 +25,9 @@ public static class Mp4Reader
|
||||
|
||||
private const int MaxTopLevelBoxes = 10_000;
|
||||
|
||||
/// <summary>The most child boxes read inside one box (real files have a few dozen).</summary>
|
||||
private const int MaxChildBoxes = 10_000;
|
||||
|
||||
/// <summary>Reads a file (read-only). Null when no <c>moov</c> box is found.</summary>
|
||||
/// <param name="path">The file.</param>
|
||||
/// <param name="now">Current time: creation times after it (by more than a day) are ignored.</param>
|
||||
@@ -72,7 +75,8 @@ public static class Mp4Reader
|
||||
size = length - position; // to the end of the file
|
||||
}
|
||||
|
||||
if (size < headerSize || position + size > length + 8)
|
||||
// Compared without adding to the position: a 64-bit size close to 2^63 would overflow the sum and pass.
|
||||
if (size < headerSize || size > length - position + 8)
|
||||
{
|
||||
return null; // damaged
|
||||
}
|
||||
@@ -193,7 +197,7 @@ public static class Mp4Reader
|
||||
{
|
||||
var list = new List<(string, int, int)>();
|
||||
var offset = 0;
|
||||
while (offset + 8 <= data.Length)
|
||||
while (offset + 8 <= data.Length && list.Count < MaxChildBoxes)
|
||||
{
|
||||
long size = BinaryPrimitives.ReadUInt32BigEndian(data.Slice(offset, 4));
|
||||
var type = System.Text.Encoding.Latin1.GetString(data.Slice(offset + 4, 4));
|
||||
@@ -208,7 +212,9 @@ public static class Mp4Reader
|
||||
size = data.Length - offset;
|
||||
}
|
||||
|
||||
if (size < headerSize || offset + size > data.Length)
|
||||
// «size > remaining» cannot overflow (unlike «offset + size»), and with «size >= headerSize» it keeps the
|
||||
// offset moving forward: a damaged 64-bit size can neither loop back nor run past the end.
|
||||
if (size < headerSize || size > data.Length - offset)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user