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

Segmentation fault on Ubuntu #278

Open
gbook opened this issue Feb 21, 2025 · 2 comments
Open

Segmentation fault on Ubuntu #278

gbook opened this issue Feb 21, 2025 · 2 comments
Assignees

Comments

@gbook
Copy link

gbook commented Feb 21, 2025

I'm writing a program using bit7z, that runs fine on Windows 11 and on Redhat 8. But when I build and run on Ubuntu 24, it segfaults. The error is occuring in a function that extracts a single file from the archive into memory. I think I'm not copying the buffer correctly... but I'm not sure why it's different between Windows, Redhat 8, and Ubuntu 24.

bool squirrel::ExtractArchiveFileToMemory(QString archivePath, QString filePath, QString &fileContents) {
    try {
        using namespace bit7z;
        std::vector<unsigned char> buffer;
        Bit7zLibrary lib(p7zipLibPath.toStdString());
        if (archivePath.endsWith(".zip", Qt::CaseInsensitive)) {
            BitFileExtractor extractor(lib, BitFormat::Zip);
            extractor.extractMatching(archivePath.toStdString(), filePath.toStdString(), buffer);
        }
        else {
            BitFileExtractor extractor(lib, BitFormat::SevenZip);
            extractor.extractMatching(archivePath.toStdString(), filePath.toStdString(), buffer);
        }
        // ----- It might be crashing here -----
        std::string str{buffer.begin(), buffer.end()};
        fileContents = QString::fromStdString(str);
        return true;
    }
    catch ( const bit7z::BitException& ex ) {
        /* Do something with ex.what()...*/
        fileContents = "Unable to extract file from archive using bit7z library [" + QString(ex.what()) + "]";
        return false;
    }
}

The segfault error within gdb

Program received signal SIGSEGV, Segmentation fault.
0x0000555555645287 in bit7z::BitInputArchive::BitInputArchive(bit7z::BitAbstractArchiveHandler const&, std::filesystem::__cxx11::path const&) ()
(gdb)
@rikyoz rikyoz self-assigned this Feb 22, 2025
@rikyoz
Copy link
Owner

rikyoz commented Feb 22, 2025

Hi!
Usually, such segmentation faults are due to a mismatch in the 7-Zip's interfaces used by bit7z and the ones provided by the 7z.so library being used.

Since 7-Zip's 23.01, the interfaces provided by the 7z.so are incompatible with the ones from the previous versions of 7-Zip or from the p7zip project.
The result is that if you build bit7z for the latest versions of 7-Zip, and then use your program with an old 7z.so, a segmentation fault will occur; and viceversa, the same result occurs if you build bit7z for older versions of 7-Zip or for p7zip, and then use a recent 7z.so.

By default, bit7z is compatible with the 7z.so from 7-Zip v23.01 and later.
You can configure bit7z differently either by specifying the correct version of 7-Zip you plan to use with your program (e.g., -DBIT7Z_7ZIP_VERSION=22.01) or by specifying whether to use the legacy interfaces or not (e.g., -DBIT7Z_USE_LEGACY_IUNKNOWN=ON or OFF).

@rikyoz
Copy link
Owner

rikyoz commented Feb 23, 2025

To clarify it further, this change happened only on Linux and macOS. On Windows, 7-Zip's interfaces never changed in an incompatible way, so you can use bit7z with any version of the 7z.dll.

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

2 participants