OOME when creating new com.aspose.words.Document with encrypted Word doc

When trying to create a new com.aspose.words.Document Java object from a Word document that was encrypted in a manner different from Word’s password protection, it appears that this causes Aspose to possibly go into an infinite loop of some kind, as it ends up causing an OOME. Below is the call stack. We are using Aspose Words version 20.10. Any help on this, or even confirmation on what is supported and what isn’t with regards to this, would be much appreciated. Thanks.

java/lang/String.(String.java:845(Compiled Code))
java/lang/String.substring(String.java:2713(Compiled Code))
com/aspose/words/zzYO0.zzZ(Bytecode PC:57(Compiled Code))
com/aspose/words/zzYO0.visitRun(Bytecode PC:65(Compiled Code))
com/aspose/words/Run.accept(Bytecode PC:2(Compiled Code))
com/aspose/words/CompositeNode.acceptChildren(Bytecode PC:16(Compiled Code))
com/aspose/words/CompositeNode.acceptCore(Bytecode PC:51(Compiled Code))
com/aspose/words/Paragraph.accept(Bytecode PC:2(Compiled Code))
com/aspose/words/CompositeNode.acceptChildren(Bytecode PC:16(Compiled Code))
com/aspose/words/CompositeNode.acceptCore(Bytecode PC:51(Compiled Code))
com/aspose/words/Body.accept(Bytecode PC:2)
com/aspose/words/CompositeNode.acceptChildren(Bytecode PC:16(Compiled Code))
com/aspose/words/CompositeNode.acceptCore(Bytecode PC:51(Compiled Code))
com/aspose/words/Section.accept(Bytecode PC:2)
com/aspose/words/CompositeNode.acceptChildren(Bytecode PC:16(Compiled Code))
com/aspose/words/CompositeNode.acceptCore(Bytecode PC:51(Compiled Code))
com/aspose/words/Document.accept(Bytecode PC:2)
com/aspose/words/zzYNQ .zzLj(Bytecode PC:221)
com/aspose/words/Document.zzY(Bytecode PC:173)
com/aspose/words/Document.zzZ(Bytecode PC:79)
com/aspose/words/Document.(Bytecode PC:22)
com/aspose/words/Document.(Bytecode PC:3)
com/aspose/words/Document.(Bytecode PC:5)

@jmyszka can you please attach the source file?

encryptedTest.docx (8.4 MB)

Thanks for the quick reply.

@jmyszka
I cannot reproduce exactly your problem, I’m using the version 23.1 of Aspose.Words, and I was able to load the file and clone it to another Document object, but I got the same exception when I save it.
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.

Issue ID(s): WORDSNET-25034

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.

@jmyszka I have closed the defect WORDSNET-25034 created by Eduardo, since Aspose.Words cannot load such encrypted document. It detects it as TEXT document. To load the document it should be first decrypted.

FYI @eduardo.canal

@alexey.noskov the main problem is that it is consuming a lot of heap, leading to an OOME. In my version 20.10, I am unable to verify if just a little more heap is needed before an IncorrectPasswordException, or any exception in general, is thrown, or if the heap would just keep growing due to some infinite loop.

The point is that we were hoping that it would just reject the file instead of causing an OOME.

To clarify, we are seeing that the process does complete with an exception, but it takes a massive amount of heap, and a long time to process it. This heavily slows down the related server in meantime, and if anyone else tries to do the same thing during that time, it can lead to an OOME.

So, the main two complaints are the amount of heap and time it takes prior to rejecting the file.

Thanks.

@jmyszka You can implement IDocumentLoadingCallback and skip loading document if it take too much time. For example see the following code:

LoadOptions opt = new LoadOptions();
opt.setProgressCallback(new LoadingProgressCallback());
try
{
    Document doc = new Document("C:\\Temp\\in.docx", opt);
}
catch (IllegalStateException exception)
{
    System.out.println(exception.getMessage());
    // Handle loading duration issue.
}
private static class LoadingProgressCallback implements IDocumentLoadingCallback
{
    /// <summary>
    /// Ctr.
    /// </summary>
    public LoadingProgressCallback()
    {
        mLoadingStartedAt = new Date();
    }

    /// <summary>
    /// Callback method which called during document loading.
    /// </summary>
    /// <param name="args">Loading arguments.</param>
    public void notify(DocumentLoadingArgs args)
    {
        Date canceledAt = new Date();
        long diff = canceledAt.getTime() - mLoadingStartedAt.getTime();
        long ellapsedSeconds = TimeUnit.MILLISECONDS.toSeconds(diff);

        if (ellapsedSeconds > MAX_DURATION)
            throw new IllegalStateException(MessageFormat.format("EstimatedProgress = {0}; CanceledAt = {1}", args.getEstimatedProgress(), canceledAt));
    }

    /// <summary>
    /// Date and time when document loading is started.
    /// </summary>
    private Date mLoadingStartedAt;

    /// <summary>
    /// Maximum allowed duration in sec.
    /// </summary>
    private static final double MAX_DURATION = 0.5;
}

The issues you have found earlier (filed as WORDSNET-25034) have been fixed in this Aspose.Words for Java 23.3 update.