fix(codecs): size JPEG bit-writer buffers in 64-bit arithmetic

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-02 10:14:41 +00:00
1 parent f2c0709ef2
commit 6aacaff882
2 files changed
+2 -2

No files matched your search

+1 -1
View File
@@ -161,7 +161,7 @@ public static class JpegEncoder
acC = new JpegHuffmanCode(JpegTables.AcChromaBits, JpegTables.AcChromaValues);
}
var writer = new JpegBitWriter(width * height * components / 4);
var writer = new JpegBitWriter((int)Math.Min(1 << 30, (long)width * height * components / 4));
Entropy(plan, o.RestartInterval, writer, null, [dcY, acY, dcC, acC]);
WriteHeaders(output, plan, o, dcY, acY, dcC, acC);
output.Write(writer.Written);
@@ -31,7 +31,7 @@ public static class JpegLosslessEncoder
var codes = new JpegHuffmanCode[components];
for (var c = 0; c < components; c++) codes[c] = JpegHuffmanCode.Optimal(counter.Frequencies[c]);
var emitter = new Emitter { Writer = new JpegBitWriter(width * height * components), Codes = codes };
var emitter = new Emitter { Writer = new JpegBitWriter((int)Math.Min(1 << 30, (long)width * height * components)), Codes = codes };
Walk(samples, layout, ref emitter);
emitter.Writer.Flush();