DocumentPrivilege is not thread safe!

The documentation for PdfFileSecurity.SetPrivilege says we’re supposed to use DocumentPrivilege now instead of the PdfPrivilege enum. However, DocumentPrivilege has a serious thread safety flaw in its design. It is a reference type (i.e., a class) not a value type (i.e., a struct), so assigning one of the static fields from it DOES NOT give you a local copy. It gives you a reference to the static field’s instance, and it provides properties that let you modify the static field’s state.


DocumentPrivilege priv = DocumentPrivilege.AllowAll;
priv.AllowCopy = false;

if (!DocumentPrivilege.AllowAll.AllowCopy)
{
throw new InvalidOperationException(“Design flaw: global static data modified!”);
}

In this example, I want to change the AllowCopy property on a local instance of DocumentPrivilege, but changing its property value also changes the static instance’s value since both references point to the same instance. This makes the DocumentPrivilege class useless in a multi-threaded environment because you can’t count on any of the pre-defined fields having a known state, and the class doesn’t provide a constructor to create your own local instances.

All of the Aspose examples for DocumentPrivilege are also broken because of this design flaw. For example:

//Way2: Based on a predefined privilege and change some specifical permissions.
DocumentPrivilege privilege = DocumentPrivilege.AllowAll;
privilege.AllowPrint = false;
privilege.AllowModifyContents = false;

This “Way2” sample has just changed the global state of the AllowAll static field, which is very bad.

Hi Bill,

Thank you very much for considering Aspose.

The issue you raised has been logged as PDFKITNET-10062 in our issue tracking system. Our development team will be looking into the matter and you’ll be updated accordingly via this forum.

We’re sorry for any inconvenience.
Regards,

The issues you have found earlier (filed as 10062) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.