PDF document randomly malformed after encryption and reloading

We found another bug that could be reproduced on Aspose.PDF 21.1.0.0. Execution results are not consistent: execution fails in 10-20% of the cases.
Source document:
document.pdf (489.1 KB)
Processing code:
public static bool validate(Aspose.Pdf.Document pdfDocument)
{
bool result = true;
try
{
foreach (Aspose.Pdf.Page pdfPage in pdfDocument.Pages)
{
Aspose.Pdf.Text.TextBuilder builder = new Aspose.Pdf.Text.TextBuilder(pdfPage);
}
}
catch
{
result = false;
}

        return result;
    }

    static void Main(string[] args)
    {
        for (int i = 0; i < 50; i++)
        {
            Aspose.Pdf.Document asposePDFDocument = new Aspose.Pdf.Document(@"document.pdf");
            asposePDFDocument.Encrypt("", "AnyPassword", Aspose.Pdf.Facades.DocumentPrivilege.Print, Aspose.Pdf.CryptoAlgorithm.AESx128, false);

            //Saving the document to the stream
            System.IO.MemoryStream memoryStreamValidate = new System.IO.MemoryStream();
            asposePDFDocument.Save(memoryStreamValidate);

            // Reloading the document
            asposePDFDocument = new Aspose.Pdf.Document(memoryStreamValidate);

            bool isValid = validate(asposePDFDocument);

            Console.WriteLine("Attempt {0} - {1}", i + 1, isValid  ? "Success" : "Failure" );
        }

        Console.ReadLine();
    }

Execution results:
image.png (3.3 KB)

@mmrusin

We have noticed the similar issue at our end and have logged an issue under the ticket ID PDFNET-49341 in our issue tracking system. We will further look into its details and keep you posted with the status of its rectification. Please be patient and spare us some time.

We are sorry for the inconvenience.