Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack Buffer Overrun Exception when a worksheet contains a picture #812

Open
niclasbb opened this issue Mar 1, 2023 · 13 comments
Open

Stack Buffer Overrun Exception when a worksheet contains a picture #812

niclasbb opened this issue Mar 1, 2023 · 13 comments
Assignees

Comments

@niclasbb
Copy link

niclasbb commented Mar 1, 2023

I use EPPlus in a web application running in Azure.
Version of .NET Framework is 4.8.4526.0.

Accessing worksheets containing drawings of type picture makes the application to chrash.

Crashdump from Azure:

InlinedCallFrame
InlinedCallFrame
DomainNeutralILStubClass.IL_STUB_PInvoke
System.Drawing.Image.FromStream
OfficeOpenXml.Drawing.GenericImageHandler.GetImageBounds
OfficeOpenXml.ExcelImageSettings.GetImageBounds
OfficeOpenXml.Drawing.PictureStore.GetImageBounds
OfficeOpenXml.Drawing.PictureStore.AddImage
OfficeOpenXml.Drawing.PictureStore.SavePicture
OfficeOpenXml.Drawing.ExcelImage.SetImageContainer
OfficeOpenXml.Drawing.ExcelPicture..ctor
OfficeOpenXml.Drawing.ExcelDrawing.GetDrawingFromNode
OfficeOpenXml.Drawing.ExcelDrawings.AddDrawings
OfficeOpenXml.Drawing.ExcelDrawings..ctor
OfficeOpenXml.ExcelWorksheets.Delete

@JanKallman
Copy link
Contributor

Are you using the latest version of EPPlus?

@niclasbb
Copy link
Author

niclasbb commented Mar 1, 2023

Yes, version 6.1.3

@JanKallman
Copy link
Contributor

Looks like a missing GDI issue. Are you using the free tier in Azure?

@hakano14
Copy link

hakano14 commented Mar 1, 2023

No - Standard S3 Plan ( 4 vCPU and 7 GB Memory)

@JanKallman
Copy link
Contributor

Does the workbooks open correctly if you run EPPlus locally?

@hakano14
Copy link

hakano14 commented Mar 1, 2023

Yes - everything works perfect locally and on-premise servers. But crashes direct in Azure App Service (Windows Plan - .Net Framework).

@niclasbb
Copy link
Author

niclasbb commented Mar 1, 2023

If we remove the picture from the worksheet it works as well.

@JanKallman
Copy link
Contributor

It likely crashes here...

var img = Image.FromStream(image);

It's weird as it should catch the Exception and use the build in image handler. Also, if you use Windows it should have GDI available.
Is this your setting:
image
Do you have a more detailed stack trace of the error?

@niclasbb
Copy link
Author

niclasbb commented Mar 2, 2023

Yes that is the correct setting.

This is the file with the image causing the error. I have tried with some other images and this is the only one that fails.
Maybe there is a problem with this image?

Offermall_err.xlsx

@JanKallman
Copy link
Contributor

This is an EMF image. I wonder if Azure's GDI implementation does not support EMF's. I will try to see if I can replicate this issue. We have a build in handler for all image types, but it seems that it does not fallback on it when an exception is thrown in this case.

@JanKallman
Copy link
Contributor

Obviously the quick fix for you is to change the image to a png or jpg and see if it works.

@niclasbb
Copy link
Author

niclasbb commented Mar 3, 2023

Yes other image types seem to work.

@JanKallman
Copy link
Contributor

I will remove the usage of System.Drawing.Common in for .NET framework in the GenericImageHandler , so it will use the build-in instead (Note that .NET core, .NET 6 & 7 already uses it). This should solve this issue.

JanKallman added a commit that referenced this issue Mar 3, 2023
….Drawing.Common for .NET framework and #813-Deleting rows deleted cf and dv for full rows/columns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants