mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-10-26 16:45:09 +00:00
Backport pull request #18309 from jellyfin/release-12.z
Fix crash when a subtitle charset has no .NET encoding
Original-merge: 2f5be2df9b
Merged-by: Bond-009 <bond.009@outlook.com>
Backported-by: Bond_009 <bond.009@outlook.com>
This commit is contained in:
1 parent
054706333d
commit
f624cb4cc5
3 files changed
+49
No files matched your search
@@ -250,6 +250,7 @@
|
|||||||
- [TheDreadPirate](https://github.com/thedreaddpirate)
|
- [TheDreadPirate](https://github.com/thedreaddpirate)
|
||||||
- [Daniel Aquino](https://github.com/chino)
|
- [Daniel Aquino](https://github.com/chino)
|
||||||
- [klizas](https://github.com/klizas)
|
- [klizas](https://github.com/klizas)
|
||||||
|
- [p27ZuH6CNAdzr](https://github.com/p27ZuH6CNAdzr)
|
||||||
|
|
||||||
# Emby Contributors
|
# Emby Contributors
|
||||||
|
|
||||||
|
|||||||
@@ -188,6 +188,14 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
|||||||
|
|
||||||
_logger.LogDebug("charset {CharSet} detected for {Path}", detected.EncodingName, fileInfo.Path);
|
_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))
|
await using (stream.ConfigureAwait(false))
|
||||||
{
|
{
|
||||||
using var reader = new StreamReader(stream, detected.Encoding);
|
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()
|
private static SubtitleEncoder CreateEncoder()
|
||||||
{
|
{
|
||||||
var fixture = new Fixture().Customize(new AutoMoqCustomization { ConfigureMembers = true });
|
var fixture = new Fixture().Customize(new AutoMoqCustomization { ConfigureMembers = true });
|
||||||
|
|||||||
Reference in new issue
Block a user