QArchive
QArchive copied to clipboard
MemoryExtractor crashes or emits error
Select your issue type: (check at least one)
- [x] Bug
- [ ] Question
- [ ] Suggestion
- [ ] Other (please describe):
Describe your issue:
MemoryExtractor crashes or emits error even though the finished
signal is emitted and the file names are printed by qDebug()
.
Ways to Reproduce the issue (optional):
Here's a sample project, just run the commands in the readme and double click a file to run the memory extraction.
When (QIODevice*)&archive
is passed to MemoryExtractor constructor it crashes.
1 QIODevice::isOpen qiodevice.cpp 603 0x7ffff6deb9e4
2 QArchive::ExtractorPrivate::openArchive qarchiveextractor_p.cc 561 0x412857
3 QArchive::ExtractorPrivate::start qarchiveextractor_p.cc 374 0x4120e1
4 QArchive::ExtractorPrivate::qt_static_metacall moc_qarchiveextractor_p.cpp 198 0x40ddf2
5 QObject::event qobject.cpp 1314 0x7ffff6ee84ae
6 QApplicationPrivate::notify_helper qapplication.cpp 3632 0x7ffff7a6aa7f
7 QCoreApplication::notifyInternal2 qcoreapplication.cpp 1064 0x7ffff6ebbe3a
8 QCoreApplicationPrivate::sendPostedEvents qcoreapplication.cpp 1821 0x7ffff6ebee77
9 postEventSourceDispatch qeventdispatcher_glib.cpp 277 0x7ffff6f13d03
10 g_main_dispatch gmain.c 3381 0x7ffff5ba2e22
11 g_main_context_dispatch gmain.c 4099 0x7ffff5ba2e22
12 g_main_context_iterate gmain.c 4175 0x7ffff5ba31b8
13 g_main_context_iteration gmain.c 4240 0x7ffff5ba326f
14 QEventDispatcherGlib::processEvents qeventdispatcher_glib.cpp 423 0x7ffff6f13384
15 QEventLoop::exec qflags.h 69 0x7ffff6eba83b
16 QCoreApplication::exec qflags.h 121 0x7ffff6ec2b10
17 main main.cpp 10 0x407f88
When I pass archiveFile
directly sometimes it works sometimes it gives an error
...
Filename:: "astrology-astronomy-body-of-water-2406397.jpg"
Filename:: "beautiful-flowers-flowers-white-flowers-2395252.jpg"
QFileDevice::seek: IODevice is not open
QFileDevice::seek: IODevice is not open
An error has occured :: "QArchive::ArchiveCorrupted"
I will look into this. What OS are you in and what archive type are you trying to extract?
Wow, I forgot to link the sample project, here it is https://gitlab.com/g-fb/memory-extraction.
What OS are you in
openSUSE Tumbleweed
what archive type are you trying to extract?
There are 2 archive in the sample project, both trigger the issues.
@g-fb I don't think it's a bug with QArchive. It's a bug with the program itself. There are two types of allocation in C, C++ and pretty much every programming language (which allows you to do memory management). You allocated the QFile in Stack Memory here -> https://gitlab.com/g-fb/memory-extraction/-/blob/master/mainwindow.cpp#L53
QArchive is async so it will not block the method call. So when the QFile goes out of scope, it is destructed so the memory address becomes invalid.
Solution: Allocated the QFile in the heap with QFile *archive = new QFile(archivePath);
and then delete it later when you are done using it.
I compiled your program with my modifications and it worked like a charm.
Thanks for the explanation.
emits error even though the finished signal is emitted and the file names are printed by qDebug().
When I pass archiveFile directly sometimes it works sometimes it gives an error
Now I am getting the error even when I pass a QIODevice. It doesn't always happen, I have to open the archives a few times. ... Filename:: "astrology-astronomy-body-of-water-2406397.jpg" Filename:: "beautiful-flowers-flowers-white-flowers-2395252.jpg" QFileDevice::seek: IODevice is not open QFileDevice::seek: IODevice is not open An error has occured :: "QArchive::ArchiveCorrupted"
I can't reproduce this. In my computer it works fine. I will look into this more.
Also you can just simply pass the archive path as string to the constructor.
Can you please verify if this bug exists even if you do a fresh build in cmake.
I think I just reproduced your bug if I do the extraction continuously.... I think it's some kind of time based issue. I will look into this more.
Also you can just simply pass the archive path as string to the constructor.
Same thing happens.
Can you please verify if this bug exists even if you do a fresh build in cmake.
The sample project pulls the master branch and builds it.
I think I just reproduced your bug if I do the extraction continuously.... I think it's some kind of time based issue. I will look into this more.
Thanks.
@g-fb does this issue happen all the time or only happens when you try to extract the same file very fastly. Ex: in my case this only occurs when I double click the same entry really fast, over and over again to get this error. Otherwise it seems to work without any issues. What is the case in your case?
It doesn't happen everytime, but very often, even if I wait few seconds between extractions.
It even happens on the first extraction.
The error seems to come from QCoreApplication::processEvents();
being inside the loop.
If I move QCoreApplication::processEvents();
outside the loop I don't get the error anymore.
The error seems to come from
QCoreApplication::processEvents();
being inside the loop. If I moveQCoreApplication::processEvents();
outside the loop I don't get the error anymore.
That just means we need some delay and we are calling process events too fast.
Seems to be related with #46, the error is solved if we don't call getInfo() before start which is a bug. Will work on fixing it.
Should work now with the latest master.