I hope this message finds you well.
While using Aspose.PSD for .NET, I encountered an issue with the PSDImage.Save()
method. Please see the details below:
Failed to save PSD: Exception calling "Save" with "1" argument(s):
"Source array was not long enough. Check the source index, length, and the array's lower bounds. (Parameter 'sourceArray')"
I am working with very large, high-resolution PSD files. During the internal execution of the Save()
method, it seems that an obfuscated internal method:
at .[T](IList`1 , Int64, IList`1 , Int64 , Int64 )
is eventually calling:
System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length)
From the logs, I can see:
Private Memory: 3162.7 MB
Since this exceeds Int32.MaxValue
(=0x7FFFFFC7 (2,147,483,591)), I suspect that an Int64
parameter is being converted to Int32
internally, which may result in a negative value being passed and ultimately causing the following error:“Source array was not long enough. Check the source index, length, and the array’s lower bounds. (Parameter ‘sourceArray’)”
If my assumption is correct, it seems this issue may be a fundamental limitation of the .NET/Aspose.PSD architecture. Could you please confirm whether this analysis is correct?
Also, is there any recommended workaround to avoid this problem?
For reference, here are the relevant debug logs:
DEBUG: Final memory cleanup before saving...
DEBUG: Saving PSD with 12 converted layers
DEBUG: Current layer count: 94
DEBUG: PSD dimensions: 3508x4967
WARNING: Failed to save PSD: Exception calling "Save" with "1" argument(s): "Source array was not long enough. Check the source index, length, and the array's lower bounds. (Parameter 'sourceArray')"
DEBUG: Save exception details: MethodInvocationException
DEBUG: Inner exception: System.ArgumentException: Source array was not long enough. Check the source index, length, and the array's lower bounds. (Parameter 'sourceArray')
at System.Array.CopyImpl(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length)
at .[T](IList`1 , Int64, IList`1 , Int64 , Int64 )
...
DEBUG: Current memory usage before error:
DEBUG: Working Set: 3005.62 MB
DEBUG: Private Memory: 3162.7 MB
DEBUG: PSD instance disposed
DEBUG: Memory after cleanup - Working Set: 2742.32 MB, Private: 2867.75 MB
WARNING: ✗ Failed to process 004074e3-7c95-470e-9777-ad8955de45d7
I would greatly appreciate your guidance on whether this is indeed a limitation of the framework and whether there are any recommended best practices to work around it.
Inside the PSDImage.Save()
method in Aspose.PSD for .NET, before calling System.Array.Copy()
, if the parameters could be checked against Int32.MaxValue
, and the size divided so that System.Array.Copy()
is executed multiple times, I believe this might provide a way to avoid the error.
Thank you for your support.
Best regards,