Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mz_zip_add_mem_to_archive_file_in_place in Android will trigger the fdsan mechanism to kill the process. #319

Open
initlist opened this issue Jul 28, 2024 · 2 comments

Comments

@initlist
Copy link

My test codes

int test_zip()
    {
        mz_zip_archive zip;
        memset(&zip, 0, sizeof(zip));

        if (!mz_zip_writer_init_file(&zip, "/sdcard/hanwang/wordResult/test.zip", 0))
        {
            LOGI("Failed to initialize zip writer\n");
            return -1;
        }
        if (!mz_zip_writer_finalize_archive(&zip))
        {
            LOGE("Failed to finalize zip archive\n");
            mz_zip_writer_end(&zip);
            return -1;
        }

        for (int i = 0; i < 50; i++)
        {
            const char *str = "hello world";
            LOGI("%d add string to zip: %s\n", i, str);
            if (!mz_zip_add_mem_to_archive_file_in_place(
                    std::string("/sdcard/hanwang/wordResult/test.zip").c_str(), ("file1.txt" + std::to_string(i)).c_str(),
                    str, (mz_uint16)strlen(str),
                    NULL, 0,
                    MZ_BEST_COMPRESSION))
            {
                LOGI("Failed to add file1.txt to zip\n");
                return -1;
            }
            // sleep 1s
            // std::this_thread::sleep_for(std::chrono::seconds(1));
        }
        return 0;
        // 关闭 ZIP 文件
        if (!mz_zip_writer_finalize_archive(&zip))
        {
            LOGE("Failed to finalize zip archive\n");
            mz_zip_writer_end(&zip);
            return -1;
        }

        mz_zip_writer_end(&zip);
        LOGE("test_zip() returns 0\n");

        return 0;
    }

The above code will crash if I don't sleep. I found that fdsan is triggered because of repeated reading and writing of the same fd. If I sleep, fdsan will not be triggered.

@RealForMe
Copy link

I have also encountered the same problem. Can I avoid android_fdsan_close_with_tag by simply sleeping?

@uroni
Copy link
Collaborator

uroni commented Oct 16, 2024

Looks like an Android (bionic) issue to me.

Does this commit fix this? 11e7c39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants