Files
Chronos/tests/Chronos.Core.Tests/Raw/RawFuzzTests.cs
T
Alby96andClaude Opus 5.5 f2b58522b9
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
refactor!: rename Titano to Chronos and move CI and releases to Gitea (#6)
The owner renamed the product and moved the repository to the self-hosted
Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control,
and asked for Actions and a first automatic release with the server package
and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md).

- Chronos everywhere: a byte-exact rename of contents and paths, then a
  per-language review of the forms the old name's ending had dictated.
- Gitea instead of GitHub: the update check, licence, issue and support
  links read ChronosReleasesUrl; the update check takes the highest stable
  version, offers a pre-release build its final release and reports a
  repository it cannot see as a failed check. EULA, security policy and
  Gitea issue forms live at the repository root.
- Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release,
  nightly image and performance gates in the .NET SDK container with git
  checkout and the system SQLite. The release cross-compiles the Windows
  programs, checks their icon, version and DPI manifest, packs installers
  and zips, publishes the Gitea release and pushes the server image
  (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows
  runner (WINDOWS_RUNNER).
- New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the
  docker-exec script, which Gitea's service containers do not allow; the
  throw-away server runs without durability) and pe-check.
- Timed tests take their budget from TestTiming (CHRONOS_TEST_TIME_FACTOR,
  3 on the shared runner; the weekly performance gates keep theirs).

BREAKING CHANGE: programs, settings, data folders, file types, environment
variables and the Docker image use the new name; nothing is migrated from
Titano, which never had a release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
2026-10-23 12:45:18 +02:00

93 lines
3.9 KiB
C#

using Chronos.Core.Codecs.Raw;
using Chronos.Core.Imaging;
using Chronos.Testing;
using static Chronos.Core.Tests.Raw.NativeRawWriters;
namespace Chronos.Core.Tests.Raw;
/// <summary>Truncated and corrupted RAW files may only raise <see cref="InvalidDataException"/> (or decode).</summary>
public sealed class RawFuzzTests(TestContext context)
{
private const int W = 48, H = 32;
private static byte[] Sample(string format)
{
using var scene = SyntheticRaw.Smooth(W, H);
return format switch
{
"dng" => SyntheticDng.Write(scene, new DngSpec { TileSize = 16, OpcodeList2 = GainMapList(), OpcodeList3 = new OpcodeListBuilder().Add(3, 0, p => p.F64(0.1).F64(0).F64(0).F64(0).F64(0).F64(0.5).F64(0.5)).Build() }),
"linear.dng" => SyntheticDng.Write(scene, new DngSpec { Cfa = null, Compression = 8 }),
"cr2" => Cr2(Sensor(scene, "Canon EOS 5D Mark III", CfaPattern.Bayer("RGGB"), 80, 36, 24, 4, 2048, 16383), new RawRect(24, 4, 24 + W, 4 + H)),
"nef" => Nef(Sensor(scene, "Nikon D850", CfaPattern.Bayer("RGGB"), W, H, 0, 0, 600, 16383), 14, NefEncoding.Lossless),
"arw" => Arw(Sensor(scene, "Sony ILCE-7M3", CfaPattern.Bayer("RGGB"), 64, H, 0, 0, 512, 16000), [8000, 10400, 12900, 14100], compressed: true),
"pef" => Pef(Sensor(scene, "Pentax K-1", CfaPattern.Bayer("BGGR"), W, H, 0, 0, 512, 16383), 14, compressed: true),
_ => Raf(Sensor(scene, "Fujifilm X-T2", DemosaicTests.XTrans, W + 6, H + 6, 3, 3, 1024, 16383), DemosaicTests.XTrans, new RawRect(3, 3, 3 + W, 3 + H)),
};
}
private static byte[] GainMapList() => new OpcodeListBuilder().Add(9, 0, p =>
{
OpcodeListBuilder.Area(p, 0, 0, H, W);
p.U32(2).U32(2).F64(1).F64(1).F64(0).F64(0).U32(1).F32(1).F32(1.1f).F32(1.2f).F32(1.3f);
}).Build();
[Theory]
[Case("dng")]
[Case("linear.dng")]
[Case("cr2")]
[Case("nef")]
[Case("arw")]
[Case("pef")]
[Case("raf")]
public void TruncatedAndCorruptedFilesOnlyRaiseInvalidData(string format)
{
var file = Sample(format);
var name = "fuzz." + format.Split('.').Last();
var options = new RawDecodeOptions { Quality = DemosaicQuality.Draft, MaxDegreeOfParallelism = 1 };
using (var clean = RawDecoder.Decode(new MemoryStream(file), name, options)) Assert.Equal(format == "arw" ? 64 : W, clean.Image.Width);
var random = new Random(format.Length * 7919);
var outcomes = new Dictionary<string, int>();
for (var i = 0; i < 120; i++)
{
byte[] variant;
if (i < 40)
{
variant = file[..(int)((long)file.Length * i / 40)];
}
else
{
variant = (byte[])file.Clone();
var flips = 1 + random.Next(4);
for (var k = 0; k < flips; k++)
{
// Bias corruption toward the headers, where structure lives.
var at = random.Next(2) == 0 ? random.Next(int.Min(variant.Length, 512)) : random.Next(variant.Length);
variant[at] = (byte)random.Next(256);
}
}
var outcome = Run(variant, name, options);
outcomes[outcome] = outcomes.GetValueOrDefault(outcome) + 1;
}
context.Log($"{format}: " + string.Join(", ", outcomes.Select(o => $"{o.Key} {o.Value}")));
}
private static string Run(byte[] data, string name, RawDecodeOptions options)
{
try
{
RawDecoder.Probe(new MemoryStream(data), name);
using var result = RawDecoder.Decode(new MemoryStream(data), name, options);
return "decoded";
}
catch (InvalidDataException)
{
return "invalid";
}
catch (Exception ex)
{
Assert.Fail($"{ex.GetType().Name}: {ex.Message}\n{ex.StackTrace}");
return "";
}
}
}