Android-TiffBitmapFactory icon indicating copy to clipboard operation
Android-TiffBitmapFactory copied to clipboard

fdsan: attempted to close file descriptor 81, expected to be unowned, actually owned by ParcelFileDescriptor 0xebcfa4c

Open therealbluepandabear opened this issue 2 years ago • 3 comments

I am getting the following when trying to decode a TIFF file:

2022-08-11 17:47:41.526 9426-9426/com.therealbluepandabear.pixapencil A/libc: fdsan: attempted to close file descriptor 81, expected to be unowned, actually owned by ParcelFileDescriptor 0xebcfa4c
2022-08-11 17:47:41.526 9426-9426/com.therealbluepandabear.pixapencil A/libc: Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 9426 (bear.pixapencil), pid 9426 (bear.pixapencil)

Code:

TiffBitmapFactory.decodeFileDescriptor(parcelFileDescriptor.fd, options)

therealbluepandabear avatar Aug 11 '22 05:08 therealbluepandabear

Check is this FileDescriptor not opened in one more place.

Beyka avatar Aug 13 '22 08:08 Beyka

@Beyka I don't think it is.

therealbluepandabear avatar Aug 18 '22 05:08 therealbluepandabear

Here's the full code:

    fun getBitmapFromUri(
        uri: Uri,
        onTaskFinished: (OutputCode, Bitmap?, String?) -> Unit) {
        var outputCode = OutputCode.Success
        var bitmap: Bitmap? = null
        var exceptionMessage: String? = null

        try {
            val contentResolver = context.applicationContext.contentResolver
            val parcelFileDescriptor: ParcelFileDescriptor = contentResolver.openFileDescriptor(uri, "r")!!

            bitmap = TiffBitmapFactory.decodeFileDescriptor(parcelFileDescriptor.fd, null)
            parcelFileDescriptor.close()
        } catch (ioException: IOException) {
            exceptionMessage = ioException.message
            outputCode = OutputCode.Failure
        } finally {
            onTaskFinished(outputCode, bitmap, exceptionMessage)
        }
    }

therealbluepandabear avatar Aug 18 '22 05:08 therealbluepandabear

Same thing happens to me. Occurs on android 11 and later. It seems that the reason is that it is closed in the destructor of NativeDecoder. NativeDecoder::~NativeDecoder() { LOGI("Destructor"); if (image) { TIFFClose(image); image = NULL; }

adachi-hideki avatar Oct 14 '22 09:10 adachi-hideki

Is there any way to fix it?

therealbluepandabear avatar Oct 14 '22 22:10 therealbluepandabear

This is clearly a remnant of decodePath, so if you specify the filedescriptor of parcelFileDescriptor, deleting it without permission is a bug, so I would like you to fix it. I don't know the impact on others, but if it's only decoding, it can be avoided by using the NDK that ndk-builds the one that commented out "TIFFClose(image)" from the destructor of NativeDecoder, but it's a little troublesome.

adachi-hideki avatar Oct 15 '22 00:10 adachi-hideki

@therealbluepandabear @adachi-hideki Deleted closing of IMAGE in native if it was oppened from FD. Please try 0.9.9.1 build

Beyka avatar Oct 21 '22 09:10 Beyka

@therealbluepandabear @adachi-hideki Deleted closing of IMAGE in native if it was oppened from FD. Please try 0.9.9.1 build

Thanks I'll try it :)

therealbluepandabear avatar Oct 21 '22 09:10 therealbluepandabear

@therealbluepandabear is it works? If yes - I will close this issue

Beyka avatar Nov 28 '22 14:11 Beyka

@therealbluepandabearそれは動作しますか?はいの場合 - この問題をクローズします

Yes. Thank you very much.

adachi-hideki avatar Nov 29 '22 02:11 adachi-hideki

I quit android dev, but I trust that it's probably fixed, this can be closed.

therealbluepandabear avatar Nov 29 '22 02:11 therealbluepandabear