HEVC e HEIF: limiti di memoria contro i file danneggiati e correzioni della revisione (#58)
Un flusso HEVC di pochi byte poteva far allocare gigabyte: ora un SPS il cui buffer supera il MaxDpbSize del livello 6.2 è rifiutato, il buffer non cresce oltre quanto l'SPS dichiara e una sola immagine grigia, riusata, sta per ogni riferimento mancante (il POC viaggia nelle liste). Nei file HEIF ogni immagine deve avere la dimensione del suo ispe, controllata dal decodificatore prima di allocare; i riquadri di una griglia devono coprire l'uscita senza traboccare, i loro byte non superano il file né MaxTotalBytes, e ciò che va storto nei riquadri decodificati in parallelo esce come HeifException. Inoltre: SPS e PPS ripetuti identici dentro un'immagine sono accettati (7.4.2.4.4) e uno cambiato vale dall'immagine dopo; le estensioni SCC sono rifiutate subito; l'intervallo di luma_offset segue l'alta precisione; YCgCo convertito, le altre matrici approssimate e documentate. «Oggetto» e «riquadro» al posto di «elemento» e «tessera» per HEIF (glossario). Righe nuove in decisioni.md: limiti, righe superate, consegne al binario dei documenti, piano per NSIS, Node e tini. Prove nuove su flussi HEVC scritti bit per bit con un codificatore CABAC di prova, su file HEIF costruiti apposta e sulla conversione YCgCo. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ac85d1baed
commit
7b10f4ad4c
16 files changed
+1389
-131
No files matched your search
@@ -108,6 +108,13 @@ internal sealed class HeifBuilder
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>Adds an item whose only extent is that of item <paramref name="dataOf"/>: the same bytes of the file.</summary>
|
||||
public HeifBuilder ItemSharing(uint id, string type, uint dataOf, params int[] properties)
|
||||
{
|
||||
items.Add(new Entry(id, type, [], properties) { SharesWith = dataOf });
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>Adds a property box and returns its 1-based index.</summary>
|
||||
public int Property(byte[] box)
|
||||
{
|
||||
@@ -156,7 +163,7 @@ internal sealed class HeifBuilder
|
||||
var meta = Meta(0);
|
||||
var mdatStart = ftyp.Length + meta.Length + 8;
|
||||
meta = Meta(mdatStart);
|
||||
var payload = InIdat ? [] : items.SelectMany(i => i.Data).ToArray();
|
||||
var payload = InIdat ? [] : items.Where(i => i.SharesWith is null).SelectMany(i => i.Data).ToArray();
|
||||
return [.. ftyp, .. meta, .. Box("mdat", payload)];
|
||||
}
|
||||
|
||||
@@ -171,15 +178,22 @@ internal sealed class HeifBuilder
|
||||
var iloc = new List<byte> { 0x44, 0x00 };
|
||||
iloc.AddRange(U16((ushort)items.Count));
|
||||
var offset = InIdat ? 0 : mdatStart;
|
||||
var extents = new Dictionary<uint, (int Offset, int Length)>();
|
||||
foreach (var item in items.Where(i => i.SharesWith is null))
|
||||
{
|
||||
extents[item.Id] = (offset, item.Data.Length);
|
||||
offset += item.Data.Length;
|
||||
}
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
var (start, length) = extents[item.SharesWith ?? item.Id];
|
||||
iloc.AddRange(U16((ushort)item.Id));
|
||||
iloc.AddRange(U16(InIdat ? (ushort)1 : (ushort)0)); // construction_method
|
||||
iloc.AddRange(U16(0));
|
||||
iloc.AddRange(U16(1));
|
||||
iloc.AddRange(U32((uint)offset));
|
||||
iloc.AddRange(U32((uint)item.Data.Length));
|
||||
offset += item.Data.Length;
|
||||
iloc.AddRange(U32((uint)start));
|
||||
iloc.AddRange(U32((uint)length));
|
||||
}
|
||||
|
||||
var ipma = new List<byte>();
|
||||
@@ -214,7 +228,7 @@ internal sealed class HeifBuilder
|
||||
children.Add(iprp);
|
||||
if (InIdat)
|
||||
{
|
||||
children.Add(Box("idat", [.. items.SelectMany(i => i.Data)]));
|
||||
children.Add(Box("idat", [.. items.Where(i => i.SharesWith is null).SelectMany(i => i.Data)]));
|
||||
}
|
||||
|
||||
return FullBox("meta", 0, [.. children.SelectMany(b => b)]);
|
||||
@@ -235,5 +249,8 @@ internal sealed class HeifBuilder
|
||||
|
||||
private static byte[] U32(uint v) => [(byte)(v >> 24), (byte)(v >> 16), (byte)(v >> 8), (byte)v];
|
||||
|
||||
private sealed record Entry(uint Id, string Type, byte[] Data, int[] Properties);
|
||||
private sealed record Entry(uint Id, string Type, byte[] Data, int[] Properties)
|
||||
{
|
||||
public uint? SharesWith { get; init; }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user