Arithmetic operations resulted in an overflow

I’ve seen similar topics here before, but not with a public answer (at least that I’ve noticed.)

I get the error in the subject line when attempting to convert an AVIF image to JPEG (or PNG). I’m using the code almost straight from the example page (Convert images AVIF to JPG via C# | products.aspose.com). I first download the AVIF from an Azure blob storage container and save it locally (this part works) and then attempt to convert that saved file to a JPEG with the following code:

using (var image = Aspose.Imaging.Image.Load(tempFolderPath + @"\tmp.avif"))
{
    var exportOptions = new Aspose.Imaging.ImageOptions.JpegOptions();
    image.Save(tmpJPGPath, exportOptions);
}

The error throws on the image.Save() line. It doesn’t appear to matter what the starter image is. I’ve downloaded multiple AVIF files and all throw the same error when I attempt to save.

@rlasbury

The “Arithmetic operations resulted in an overflow” error you are encountering when converting an AVIF image to JPEG or PNG may arise from various factors, including potential issues with the image file itself or the conversion process.

Here are some troubleshooting steps you can take:

  1. Check the AVIF File: Verify that the AVIF file is not corrupted. Open it with an image viewer to ensure it displays correctly.

  2. Update Aspose.Imaging: Ensure you are using the latest version of Aspose.Imaging, as newer releases may contain bug fixes that could resolve your issue.

  3. Use Different Export Options: Experiment with different options for saving the image. For instance, you can specify the quality of the JPEG image:

    using (var image = Aspose.Imaging.Image.Load(tempFolderPath + @"\tmp.avif"))
    {
        var exportOptions = new Aspose.Imaging.ImageOptions.JpegOptions
        {
            Quality = 90 // Adjust quality as needed
        };
        image.Save(tmpJPGPath, exportOptions);
    }
    
  4. Test with Other AVIF Files: If possible, try converting different AVIF files to determine if the issue is specific to certain files.

  5. Check System Resources: Ensure that your system has sufficient memory and resources available, as an overflow can occur due to inadequate resources.

If the problem persists after trying these steps, consider reaching out to Aspose support with details about the AVIF files you are using and the specific version of Aspose.Imaging you have.

I tried option 3 from above and now I get a different error, though still on the image.Save() step. The new error is “Index was outside the bounds of the array.” I’ve tried multiple AVIF files, all result in the same error. I’ve tried converting from AVIF to PNG and also get the same error. Below is the callstack:

Aspose.Imaging.CoreExceptions.ImageSaveException
HResult=0x80131500
Message=Image saving failed.
Source=Aspose.Imaging
StackTrace:
at Aspose.Imaging.Image.Save(String filePath, ImageOptionsBase options, Rectangle boundsRectangle)
at Aspose.Imaging.Image.Save(String filePath, ImageOptionsBase options)
at FNSBArcGISProAddin.PI.PropertyInspectorDockPaneView.<>c__DisplayClass18_0.<<BtnGenReport_Click>b__1>d.MoveNext() in C:\Users\roger.asbury\source\repos\gis-arcgispro-addin\FNSBArcGISProAddin\PropertyInspector\PropertyInspectorDockPane.xaml.cs:line 907
at FNSBArcGISProAddin.PI.PropertyInspectorDockPaneView.<BtnGenReport_Click>d__18.MoveNext() in C:\Users\roger.asbury\source\repos\gis-arcgispro-addin\FNSBArcGISProAddin\PropertyInspector\PropertyInspectorDockPane.xaml.cs:line 652
at System.Threading.Tasks.Task.<>c.b__128_0(Object state)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
— End of stack trace from previous location —
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at ArcGISPro.Program.Run()
at ArcGISPro.Program.Main(String[] args)

This exception was originally thrown at this call stack:
dje_qWNQ73WMNUTWAD658FFYG5NLKB2XSK5YGVDB7JB6FNYMYE2MN4FUQ_ejd.#=ztHK$iIa0fTb6rcRLIp_WPlBp0hzy(object)
dje_qWNQ73WMNUTWAD658FFYG5NLKB2XSK5YGVDB7JB6FNYMYE2MN4FUQ_ejd.#=zLuX87ir_jb0Jka6VP8lLvIthnMBd(object)
dje_qWNQ73WMNUTWAD658FFYG5NLKB2XSK5YGVDB7JB6FNYMYE2MN4FUQ_ejd.#=z09Qh$LMVXy2zfcvFnh2jY5yde4LF()
dje_qWNQ73WMNUTWAD658FFYG5NLKB2XSK5YGVDB7JB6FNYMYE2MN4FUQ_ejd.#=zHttYFF8Hbcf61FwETgO_hMzIITMMdjdsYXv2KBg=(object, uint)
dje_qWNQ73WMNUTWAD658FFYG5NLKB2XSK5YGVDB7JB6FNYMYE2MN4FUQ_ejd.#=zF0bob$cB8DBzc9NkXBodZM8hMAZE(bool)
dje_qWNQ73WMNUTWAD658FFYG5NLKB2XSK5YGVDB7JB6FNYMYE2MN4FUQ_ejd.#=zF0bob$cB8DBzc9NkXBodZM8hMAZE(bool)
dje_qWNQ73WMNUTWAD658FFYG5NLKB2XSK5YGVDB7JB6FNYMYE2MN4FUQ_ejd.#=z$U2ngHgsj30bZ7whRlEhCL2IjXsQf0URUgJQYittIlig(object[], System.Type[], System.Type[], object[])
dje_qWNQ73WMNUTWAD658FFYG5NLKB2XSK5YGVDB7JB6FNYMYE2MN4FUQ_ejd.#=zCSishpiJUvlElPMQrOkm7ZUxoR$UCIp62GDly5c=(System.IO.Stream, string, object[], System.Type[], System.Type[], object[])
dje_qWNQ73WMNUTWAD658FFYG5NLKB2XSK5YGVDB7JB6FNYMYE2MN4FUQ_ejd.#=zhxyM7oaSVD9dJudeuUHdmOE=(System.IO.Stream, string, object[])
dje_qWNQ73WMNUTWAD658FFYG5NLKB2XSK5YGVDB7JB6FNYMYE2MN4FUQ_ejd.#=zUJ066xlQF0PcipJ38aKSUQuOQ6iP(System.IO.Stream, string, object[])

[Call Stack Truncated]

Inner Exception 1:
ImageSaveException: Image export failed.

Inner Exception 2:
IndexOutOfRangeException: Index was outside the bounds of the array.

Hi @rlasbury ,
We are sorry that you faced the issue.
Could you provide the file that fails?