mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-10-26 16:45:09 +00:00
Merge pull request #18309 from p27ZuH6CNAdzr/fix-2200-SubtitleEncoder-nonsense
Fix crash when a subtitle charset has no .NET encoding
This commit is contained in:
1 parent
2002095e0f
commit
2f5be2df9b
3 files changed
+49
No files matched your search
@@ -249,6 +249,7 @@
|
||||
- [TheDreadPirate](https://github.com/thedreaddpirate)
|
||||
- [Daniel Aquino](https://github.com/chino)
|
||||
- [klizas](https://github.com/klizas)
|
||||
- [p27ZuH6CNAdzr](https://github.com/p27ZuH6CNAdzr)
|
||||
|
||||
# Emby Contributors
|
||||
|
||||
|
||||
@@ -188,6 +188,14 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
||||
|
||||
_logger.LogDebug("charset {CharSet} detected for {Path}", detected.EncodingName, fileInfo.Path);
|
||||
|
||||
// If encoding is not supported by .NET (e.g., ISO-8859-16), return stream as-is
|
||||
// The charset name will be passed to ffmpeg via -sub_charenc if needed
|
||||
if (detected.Encoding is null)
|
||||
{
|
||||
_logger.LogWarning("Encoding {Encoding} is not supported by .NET for {Path}, returning stream as-is", detected.EncodingName, fileInfo.Path);
|
||||
return stream;
|
||||
}
|
||||
|
||||
await using (stream.ConfigureAwait(false))
|
||||
{
|
||||
using var reader = new StreamReader(stream, detected.Encoding);
|
||||
|
||||
@@ -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<SubtitleEncoder>();
|
||||
|
||||
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 });
|
||||
|
||||
Reference in new issue
Block a user