We're sorry GroupDocs doesn't work properply without JavaScript enabled.

Free Support Forum - groupdocs.com

Application Crash on Linux when Processing a File with a Form Element using C#

When processing this file test.docx (37.6 KB) on Linux, our service is killed with an unhandled exception from SkiaSharp. The stack trace does not contain any of our code, and can’t seem to be trapped (the triggering code is in a try-catch, and nothing is caught).

The service threw an unhandled exception, System.ArgumentNullException: Value cannot be null. (Parameter 'buffer')
       at SkiaSharp.SKManagedStream.OnReadManagedStream(IntPtr buffer, IntPtr size)
       at SkiaSharp.SKManagedStream.OnRead(IntPtr buffer, IntPtr size)
       at SkiaSharp.SKAbstractManagedStream.ReadInternal(IntPtr s, Void* context, Void* buffer, IntPtr size)

Removing the form element (the checkbox in the grey area near the top) and the file processes successfully. Other documents process successfully on Linux. The same code on Windows can process the document successfully.

The relevant code snippet (try-catch removed):

var pages = new List<MemoryStream>();
var pageStreamFactory = new ContentPageStreamFactory(pages);
using (var viewer = new Viewer(stream))
{
     var options = new JpgViewOptions(pageStreamFactory)
     {
           Quality = 50
     };
     viewer.View(options, 1);
}

var image = Image.FromStream(pages.FirstOrDefault());

Linux version is Red Hat Enterprise Linux release 8.4 (Ootpa) 4.18.0-305.19.1.el8_4.x86_64
.NET is version 5.0.11
GroupDocs.Viewer version is 21.10.0
SkiaSharp version is 2.80.3
SkiaSharp.NativeAssets.Linux version is 2.80.3

@dsproson-1

Thank you for providing the sample file, code snippet and SkiaSharp versions. I’m able to reproduce this issue with this sample_app.zip (96.2 KB) in a Docker container with SkiaSharp.NativeAssets.Linux.NoDependencies 2.80.3.

I’ve also tried to use 2.80.2 and it worked well, can you please try running your app with SkiaSharp.NativeAssets.Linux.NoDependencies 2.80.2 instead of referencing SkiaSharp version is 2.80.3 and SkiaSharp.NativeAssets.Linux version is 2.80.3?

Thanks. That works.

@dsproson-1

Great, thanks for the response.

Unfortunately, I haven’t found any documented confirmation that the version of the SkiaSharp.NativeAssets.* should be the same as SkiaSharp version but it seems that the versions should match with the version we depend on.

Possibly we could include SkiaSharp.NativeAssets.* as a dependency in our NuGet package but according to SkiaSharp-Native-Assets-for-Linux it is not recommended:

The overall result of this is that you will do everything as usual, but in the “app” part of the solution, just add the package. You should not release a NuGet to nuget.org that depends on this directly as you will then force all your uses to use my binary.

Thanks.
The NuGet page says >= 2.80.2 - should we take that as “=” rather than latest? We can then make sure the build uses that.

@dsproson-1

This issue has been already reported to SkiaShap, the issue ID is #1846. So, for now, it would be reasonable to use 2.80.2.

@dsproson-1

This issue has been fixed in GroupDocs.Viewer 21.12. You can now use SkiaSharp.NativeAssets.Linux 2.80.3. The packages available at:

Have a nice day!

Is this fix incorporated into GroupDocs.Conversion yet? I don’t see a 21.12 version and I am getting the same error when trying to convert a DOCX on Linux.

Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'buffer')
at SkiaSharp.SKManagedStream.OnReadManagedStream(IntPtr buffer, IntPtr size)
at SkiaSharp.SKManagedStream.OnRead(IntPtr buffer, IntPtr size)
at SkiaSharp.SKAbstractManagedStream.ReadInternal(IntPtr s, Void* context, Void* buffer, IntPtr size)
at SkiaSharp.SkiaApi.sk_codec_new_from_stream(IntPtr stream, SKCodecResult* result)
at SkiaSharp.SKCodec.Create(SKStream stream, SKCodecResult& result)
at SkiaSharp.SKCodec.Create(Stream stream, SKCodecResult& result)
at SkiaSharp.SKCodec.Create(Stream stream)
at SkiaSharp.SKBitmap.Decode(Stream stream)
at   . (Byte[] )
at ​ . (Byte[] )
at    .()
Fatal error. Internal CLR error. (0x80131506)
at SkiaSharp.SkiaApi.sk_codec_new_from_stream(IntPtr, SkiaSharp.SKCodecResult*)
at SkiaSharp.SkiaApi.sk_codec_new_from_stream(IntPtr, SkiaSharp.SKCodecResult*)
at SkiaSharp.SKCodec.Create(SkiaSharp.SKStream, SkiaSharp.SKCodecResult ByRef)
at SkiaSharp.SKCodec.Create(System.IO.Stream, SkiaSharp.SKCodecResult ByRef)
at SkiaSharp.SKCodec.Create(System.IO.Stream)
at SkiaSharp.SKBitmap.Decode(System.IO.Stream)

@agilelaw

There is no 21.12 version of GroupDocs.Conversion and I believe that the next version is going to be 22.1.

This issue has been already reported to the GroupDocs.Conversion team. Please follow SkiaSharp throws unhandled exception during conversion on debian 10 / .net 5 topic for future updates.