You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
The text was updated successfully, but these errors were encountered:
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).
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.
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.
The segfault error within gdb
The text was updated successfully, but these errors were encountered: