kleisauke / net-vips

.NET binding for libvips.
https://kleisauke.github.io/net-vips/
MIT License
401 stars 32 forks source link

NetVips Image.WriteToBuffer (and possibly others) Not Working with Windows ActiveDirectory Impersonation #239

Closed ASSET5375 closed 1 month ago

ASSET5375 commented 1 month ago

Hi,

I'm using WindowsIdentity.RunImpersonated function with the SafeAccessTokenHandle to impersonate another Windows AD User. Inside, I'm using NetVips WriteToBuffer on an NetVips.Image generated using NewFromFile(FilePath) to get the Byte Array representation. This FilePath is in a Folder that has been denied all Read/Write permissions to everyone except the impersonated AD User.

WriteToBuffer errors out with the following:

unable to call VipsForeignSaveSpngTarget \Part5689\Data\TestDenied\image1.png: unable to open for read windows error: The data is invalid.

\Part5689\Data\TestDenied\image1.png: unable to open for read windows error: The data is invalid.

pngload: stream error

kleisauke commented 1 month ago

Could you reproduce this when using Image.NewFromBuffer(File.ReadAllBytes(Filename)) instead of Image.NewFromFile(Filename)? I suspect the error isn't in WriteToBuffer(), as the error message points to an issue with pngload.

Note that libvips is demand-driven, meaning all processing is deferred until the final write to file, buffer, or memory.

ASSET5375 commented 1 month ago

thanks @kleisauke that worked. Not sure why NewFromFile isn't working. I guess AD impersonation only works on direct IO calls?

kleisauke commented 1 month ago

I guess AD impersonation only works on direct IO calls?

I'm not sure.

error: The data is invalid.

Note that this error message is somewhat misleading; the actual error message is "Permission denied". Commit https://github.com/libvips/libvips/commit/ea86a0d03b05c3146b93ed210b835188334bde8a resolves this, and the fix will be available in NetVips.Native 8.16.0.