From f624cb4cc54826d4fc5c56dc2de9120a0ea632ce Mon Sep 17 00:00:00 2001 From: p27ZuH6CNAdzr <317456640+p27ZuH6CNAdzr@users.noreply.github.com> Date: Tue, 13 Oct 2026 13:36:11 -0400 Subject: Backport pull request #18309 from jellyfin/release-12.z Fix crash when a subtitle charset has no .NET encoding Original-merge: 2f5be2df9be3d9ef44af4bf787a063f4d4166629 Merged-by: Bond-009 Backported-by: Bond_009 --- .../Subtitles/SubtitleEncoderTests.cs | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'tests/Jellyfin.MediaEncoding.Tests/Subtitles/SubtitleEncoderTests.cs') diff --git a/tests/Jellyfin.MediaEncoding.Tests/Subtitles/SubtitleEncoderTests.cs b/tests/Jellyfin.MediaEncoding.Tests/Subtitles/SubtitleEncoderTests.cs index 48850b2f67..13779851a9 100644 --- a/tests/Jellyfin.MediaEncoding.Tests/Subtitles/SubtitleEncoderTests.cs +++ b/tests/Jellyfin.MediaEncoding.Tests/Subtitles/SubtitleEncoderTests.cs @@ -269,6 +269,46 @@ namespace Jellyfin.MediaEncoding.Subtitles.Tests } } + [Fact] + public async Task GetSubtitleStream_UnsupportedEncoding_DoesNotThrow() + { + // Regression test for issue #2200 + // When the charset detector identifies an encoding not supported by .NET (e.g., ISO-8859-16), + // GetSubtitleStream should handle it gracefully instead of throwing ArgumentNullException + var cancellationToken = TestContext.Current.CancellationToken; + var srt = BuildGreekSrt(); + var path = Path.GetTempFileName(); + try + { + // Write as ISO-8859-7 (Greek) to create a non-UTF-8 file + await File.WriteAllTextAsync(path, srt, Encoding.GetEncoding("iso-8859-7"), cancellationToken); + + var fixture = new Fixture().Customize(new AutoMoqCustomization { ConfigureMembers = true }); + var subtitleEncoder = fixture.Create(); + + var fileInfo = new SubtitleEncoder.SubtitleInfo + { + Path = path, + Protocol = MediaProtocol.File, + Format = "srt", + IsExternal = true + }; + + // This should not throw even if the detected encoding was unsupported + using var stream = await subtitleEncoder.GetSubtitleStream(fileInfo, cancellationToken); + Assert.NotNull(stream); + + // Verify we can read from the stream without error + using var reader = new StreamReader(stream); + var text = await reader.ReadToEndAsync(cancellationToken); + Assert.NotEmpty(text); + } + finally + { + File.Delete(path); + } + } + private static SubtitleEncoder CreateEncoder() { var fixture = new Fixture().Customize(new AutoMoqCustomization { ConfigureMembers = true }); -- cgit v1.2.3