Concurrent loading of workbooks throws spurious "File is corrupted" errors

Hi,

Using Aspose Cells for Java, version 22.8.
In our software product, we’ve seen spurious errors thrown by Aspose Cells when loading workbooks, depending on the amount of concurrent requests in the system.
The problem seems to have been introduced in version 22.7.

We were able to consistently trigger the error, in an isolated test-case, by loading the same stream of bytes (containing the content of an XLSX file) from multiple threads.

Sample code:

public class AsposeTest {
    public static void main(String[] args) throws Exception {
        byte[] bytes = Files.readAllBytes(Paths.get("input.xlsx"));
        for (int workerId = 0; workerId < 10; workerId++) {
            Thread thread = new Thread(new LoadingWorker(workerId, bytes));
            thread.start();
        }
    }

    static class LoadingWorker implements Runnable {

        private final int workerId;
        private final byte[] bytes;

        public LoadingWorker(int workerId, byte[] bytes) {
            this.workerId = workerId;
            this.bytes = bytes;
        }

        @Override
        public void run() {
            try {
                Thread.sleep((long) (Math.random() * 20));
                ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
                for (int iteration = 0; iteration < 1000; iteration++) {
                    Thread.sleep((long) (Math.random() * 20));
                    new Workbook(inputStream);
                    System.out.println(workerId + " => " + iteration);
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
}

When a only a single thread is used, no loading errors are reported.
However, when concurrency is increased, sometimes the loading of the Workbook will fail with the following exception:

Caused by: com.aspose.cells.CellsException: File is corrupted
	at com.aspose.cells.y_m.warning(Unknown Source)
	at com.aspose.cells.g6w.a(Unknown Source)
	at com.aspose.cells.e4_.a(Unknown Source)
	at com.aspose.cells.c3o.a(Unknown Source)
	at com.aspose.cells.c3o.a(Unknown Source)
	at com.aspose.cells.Workbook.a(Unknown Source)
	at com.aspose.cells.Workbook.<init>(Unknown Source)
	at x.y.z.AsposeTest$LoadingWorker.run(AsposeTest.java:40)
	... 1 more

The above stack trace is with Aspose 22.8, running on Java 8.

On Aspose Cells 22.6, it is not possible to trigger the error.

This regression, starting from Aspose Cells 22.7, is a show-stopper, as random “File is corrupted” will occur at load.

Kind regards,
Taras

Sample workbook file: input.zip (1.9 MB)

@TarasTielkes,

Thanks for the template file.

Please notice, after an initial test, I am able to reproduce the issue as you mentioned by using your template file. I found concurrent loading of workbooks throws spurious “File is corrupted” errors for some iterations. I have logged a ticket with an id “CELLSJAVA-44864” for your issue. We will look into it soon.

Once we have an update on it, we will let you know.

@TarasTielkes,

This is to inform you that your issue has been resolved now. The fix will be included in our upcoming release (Aspose.Cells v22.9) scheduled in the second week of September 2022. You will also be notified when the next version is released.

Hi @Amjad_Sahi,

It would be interesting to know, what the root cause of the regression was.
I assume it relates to the new implementation of the zip file code, which was integrated into 22.7?
Was there some missing synchronization of resources (Deflater instances, perhaps?) that made concurrent workbook loading fail?

Kind regards,
Taras

@TarasTielkes,
Yes, when processing some string contents in the zip file, we did not make the function support multi-threads operations.

Hi @Amjad_Sahi,

Just to check, is the release planned for the current week?

Thanks,
Taras

@TarasTielkes,

Yes, it is planned. Hopefully we will publish the new release before the end of this week.

The issues you have found earlier (filed as CELLSJAVA-44864) have been fixed in this update. This message was posted using Bugs notification tool by Peyton.Xu