fix(502): correct the deco-scoping claim, extract + test the routing guard
Build ErsatzTV Image / CI image pin matches docker/ci (pull_request) Successful in 13s
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 13s
Build ErsatzTV Image / decisions.md append-only (pull_request) Successful in 14s
Build CI Toolchain Image / Build & push CI image (push) Successful in 1m39s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 17s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 16s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 7m56s
Build ErsatzTV Image / Functional E2E (curl contracts) (pull_request) Successful in 15m2s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 17m48s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped

Adversarial review found a documentation defect, not a code one: both
docs/decisions.md and the WatermarkSelector comment asserted the deco path
was unaffected by this change. That is true of the *resolution* half and
false of the *routing* half. SelectWatermarks puts deco-derived options
into the same list the routing guard filters, so a deco watermark whose
resolved path is a URL is rerouted to the graphics engine too — including
the generated-initials localhost URL, which only the deco path still emits
and which plausibly rendered through ffmpeg before.

That reroute is intended (routing by what the path is beats routing by
provenance, which would drift), so the fix is to say so accurately rather
than to narrow the guard. Also records the accepted per-frame cost
asymmetry the entry previously argued on correctness grounds alone.

The guard is extracted as CanUseFFmpegNativeWatermark so it can be tested
directly — review's highest-value gap was that the half of the fix which
decides whether pixels appear had no automated coverage, only the one-off
live E2E. Nine cases pin it, including the localhost-fallback reroute.

Both deferrals now point at real issues instead of an unverifiable
"tracked separately": #510 (deco vs precedence-level missing-logo policy)
and #511 (remote-fetch hardening — timeout, size cap, redirects, pooling,
caching, SSRF).

Also pins scheme-case insensitivity in the selector.
This commit is contained in:
2026-07-20 23:00:27 +02:00
parent f9bd245158
commit 66448e1abf
5 changed files with 147 additions and 14 deletions
@@ -68,6 +68,29 @@ public class FFmpegLibraryProcessService : IFFmpegProcessService
_logger = logger;
}
/// <summary>
/// Whether ffmpeg can carry the watermark itself (a single permanent watermark and no other graphics),
/// rather than handing it to the graphics engine.
/// </summary>
/// <remarks>
/// A watermark whose resolved path is a remote URL is always refused here (#502). ffmpeg would receive it
/// as a bare <c>-i</c> argument — and <c>ffprobe</c> the same string for animation detection — putting an
/// unbounded network fetch inside stream startup, with no timeout, redirect or auth handling of ours, and
/// with the image's real dimensions never probed. The graphics engine fetches remote images deliberately
/// (<c>ImageElementBase.LoadImage</c>) and decodes them for their true size.
/// <para>
/// This is decided by the resolved <see cref="WatermarkOptions.ImagePath" /> alone, so it applies
/// uniformly however the watermark was selected — channel, global, playout item <em>or</em> deco. Only
/// `ChannelLogo` watermarks can produce a URL: `Custom` resolves through the image cache and
/// `Resource` through the resources folder, so neither is ever rerouted.
/// </para>
/// </remarks>
internal static bool CanUseFFmpegNativeWatermark(int graphicsElementCount, List<WatermarkOptions> watermarks) =>
graphicsElementCount == 0
&& watermarks.Count == 1
&& watermarks.All(wm => wm.Watermark.Mode is ChannelWatermarkMode.Permanent
&& !Artwork.IsExternalUrl(wm.ImagePath));
public async Task<PlayoutItemResult> ForPlayoutItem(
string ffmpegPath,
string ffprobePath,
@@ -379,13 +402,7 @@ public class FFmpegLibraryProcessService : IFFmpegProcessService
Option<GraphicsEngineContext> graphicsEngineContext = Option<GraphicsEngineContext>.None;
List<GraphicsElementContext> graphicsElementContexts = [];
// use ffmpeg for single permanent watermark, graphics engine for all others.
// a remote-URL watermark always takes the graphics engine (#502): that path fetches the image with
// HttpClient and reads its real dimensions, whereas this one would hand the URL to ffprobe and
// ffmpeg as a bare -i argument, putting an unbounded network fetch inside stream startup.
if (graphicsElements.Count == 0 && watermarks.Count == 1
&& watermarks.All(wm => wm.Watermark.Mode is ChannelWatermarkMode.Permanent)
&& watermarks.All(wm => !Artwork.IsExternalUrl(wm.ImagePath)))
if (CanUseFFmpegNativeWatermark(graphicsElements.Count, watermarks))
{
foreach (var wm in watermarks)
{