ArgumentOutOfRangeException when loading PSD files modified by ag-psd library

Dear Aspose.PSD developers,

I am having an issue with processing PSD files in my project. The files are created on the frontend using the ag-psd library, then uploaded to a backend service where they are loaded using Aspose.PSD for Java.

However, when I try to load the uploaded file using Aspose.PSD, it throws an exception with the following error message:

com.aspose.psd.internal.Exceptions.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: startPosition

This is the code I use on the frontend:

const files = event.target.files;
if (files.length > 0) {
  const file = files[0];
  const arrayBuffer = await file.arrayBuffer();
  const psd = readPsd(arrayBuffer);

  const imageData = writePsd(readPsd(arrayBuffer));
  const blob = new Blob([imageData], { type: 'application/octet-stream' });
  let formData = new FormData();
  formData.append('psd_file', blob, file.name);

  try {
    const response = await fetch('http://localhost:24568/psd_template', {
      method: 'POST',
      body: formData
    });
    if (response.ok) {
      console.log('Upload successful');
      console.log(response);
    } else {
      console.error('Upload failed with HTTP status', response.status);
    }
  } catch (error) {
    console.error('Upload failed with error', error);
  }
}

And this is the code on the backend with aspose.psd:

PsdImage image = (PsdImage) Image.load(saveFile.getPath());

Could you please advise me on whether there’s a way to ignore this error, work around it, or otherwise fix the problem?

I’m not sure if the problem lies with ag-psd or aspose.psd. Do you have any thoughts on this issue? I will relay the responses from ag-psd here in real time.

output.zip (9.3 MB)
The psd file for this case

Looking forward to your guidance.

Best regards.

The full exception message is as follows. This psd file can be opened normally by Photoshop. Why is this a problem? How do I get around it? Thank you.

Exception in thread “main” class com.aspose.psd.coreexceptions.ImageLoadException: Image loading failed. —> class com.aspose.psd.coreexceptions.imageformats.PsdImageResourceException: The contained resource data is not in Jpeg format. —> class com.aspose.psd.internal.Exceptions.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: startPosition
com.aspose.psd.StreamContainer.(Unknown Source)
com.aspose.psd.StreamContainer.(Unknown Source)
com.aspose.psd.StreamContainer.a(Unknown Source)
com.aspose.psd.internal.jy.x.a(Unknown Source)
com.aspose.psd.internal.iH.A.a(Unknown Source)
com.aspose.psd.internal.iH.A.a(Unknown Source)
com.aspose.psd.internal.jz.d.a(Unknown Source)
com.aspose.psd.internal.ju.a.load(Unknown Source)
com.aspose.psd.Image.a(Unknown Source)
com.aspose.psd.Image.load(Unknown Source)
pers.wofbi.refer.Test.main(Test.java:42)
— End of inner exception stack trace —
com.aspose.psd.internal.jy.x.a(Unknown Source)
com.aspose.psd.internal.iH.A.a(Unknown Source)
com.aspose.psd.internal.iH.A.a(Unknown Source)
com.aspose.psd.internal.jz.d.a(Unknown Source)
com.aspose.psd.internal.ju.a.load(Unknown Source)
com.aspose.psd.Image.a(Unknown Source)
com.aspose.psd.Image.load(Unknown Source)
pers.wofbi.refer.Test.main(Test.java:42)
— End of inner exception stack trace —
com.aspose.psd.Image.a(Unknown Source)
com.aspose.psd.Image.load(Unknown Source)
pers.wofbi.refer.Test.main(Test.java:42)
at com.aspose.psd.Image.a(Unknown Source)
at com.aspose.psd.Image.load(Unknown Source)
at pers.wofbi.refer.Test.main(Test.java:42)
Caused by: class com.aspose.psd.coreexceptions.imageformats.PsdImageResourceException: The contained resource data is not in Jpeg format. —> class com.aspose.psd.internal.Exceptions.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: startPosition
com.aspose.psd.StreamContainer.(Unknown Source)
com.aspose.psd.StreamContainer.(Unknown Source)
com.aspose.psd.StreamContainer.a(Unknown Source)
com.aspose.psd.internal.jy.x.a(Unknown Source)
com.aspose.psd.internal.iH.A.a(Unknown Source)
com.aspose.psd.internal.iH.A.a(Unknown Source)
com.aspose.psd.internal.jz.d.a(Unknown Source)
com.aspose.psd.internal.ju.a.load(Unknown Source)
com.aspose.psd.Image.a(Unknown Source)
com.aspose.psd.Image.load(Unknown Source)
pers.wofbi.refer.Test.main(Test.java:42)
— End of inner exception stack trace —
com.aspose.psd.internal.jy.x.a(Unknown Source)
com.aspose.psd.internal.iH.A.a(Unknown Source)
com.aspose.psd.internal.iH.A.a(Unknown Source)
com.aspose.psd.internal.jz.d.a(Unknown Source)
com.aspose.psd.internal.ju.a.load(Unknown Source)
com.aspose.psd.Image.a(Unknown Source)
com.aspose.psd.Image.load(Unknown Source)
pers.wofbi.refer.Test.main(Test.java:42)
at com.aspose.psd.internal.jy.x.a(Unknown Source)
at com.aspose.psd.internal.iH.A.a(Unknown Source)
at com.aspose.psd.internal.iH.A.a(Unknown Source)
at com.aspose.psd.internal.jz.d.a(Unknown Source)
Caused by: class com.aspose.psd.coreexceptions.imageformats.PsdImageResourceException: The contained resource data is not in Jpeg format. —> class com.aspose.psd.internal.Exceptions.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.

at com.aspose.psd.internal.ju.a.load(Unknown Source)
... 3 more

Caused by: class com.aspose.psd.internal.Exceptions.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: startPosition
com.aspose.psd.StreamContainer.(Unknown Source)
com.aspose.psd.StreamContainer.(Unknown Source)
com.aspose.psd.StreamContainer.a(Unknown Source)
com.aspose.psd.internal.jy.x.a(Unknown Source)
com.aspose.psd.internal.iH.A.a(Unknown Source)
com.aspose.psd.internal.iH.A.a(Unknown Source)
com.aspose.psd.internal.jz.d.a(Unknown Source)
com.aspose.psd.internal.ju.a.load(Unknown Source)
com.aspose.psd.Image.a(Unknown Source)
com.aspose.psd.Image.load(Unknown Source)
pers.wofbi.refer.Test.main(Test.java:42)
at com.aspose.psd.StreamContainer.(Unknown Source)
at com.aspose.psd.StreamContainer.(Unknown Source)
at com.aspose.psd.StreamContainer.a(Unknown Source)
… 8 more
Caused by: class com.aspose.psd.internal.Exceptions.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.

@wofbi We’ve made investigation. This issue is reproducable both Aspose.PSD for .Net and Aspose.PSD for Java, so, I created task PSDJAVA-458: File changed in the 3rd party library corrupts PSD file but it can be opened in the Photoshop. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

ETA: it will be fixed in Aspose.PSD 23.8 for .Net, so it will be fixed in Aspose.PSD for Java in September.

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Thank you. I look forward to your corrections.