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

Segfault when switching folders in file explorer #1083

Closed
scrubbbbs opened this issue May 31, 2024 · 5 comments
Closed

Segfault when switching folders in file explorer #1083

scrubbbbs opened this issue May 31, 2024 · 5 comments

Comments

@scrubbbbs
Copy link
Contributor

scrubbbbs commented May 31, 2024

Nomacs segfaults when switching between two folders in the file explorer before allowing them to finishing thumbnailing. It doesn't always happen but only takes me a few tries.

It seems like DkThumbNail::computeIntern() is always on the stack so I guess this is a race or double-free on the const QString& fileName parameter since it tends to be passed to some function that segfaults (which varies). The problem might be the assumption that QString is thread-safe, in which case the solution could be to give each thread a copy.

I think its a known bug in hibernation since there is a comment in DkThumbNail::computeIntern() about a crash though no specific details are mentioned.

Here's a couple of stack traces; both in different places but the QString filename is involved in both places.

1  QDir::fromNativeSeparators(QString const&)                                                                                                                                  0x7795b3bdcb5d 
2  QFileInfo::QFileInfo(QString const&)                                                                                                                                        0x7795b3bf1157 
3  nmc::DkThumbNail::computeIntern                                                                                                        DkThumbs.cpp                     132 0x7795b57ec076 
4  nmc::DkThumbNailT::computeCall                                                                                                         DkThumbs.cpp                     324 0x7795b57ed610 
5  operator()                                                                                                                             DkThumbs.cpp                     316 0x7795b57ed07c 
6  QtConcurrent::StoredFunctorCall0<QImage, nmc::DkThumbNailT::fetchThumb(int, QSharedPointer<QByteArray>)::<lambda()>>::runFunctor(void) qtconcurrentstoredfunctioncall.h 60  0x7795b57edbc4 
7  QtConcurrent::RunFunctionTask<QImage>::run                                                                                             qtconcurrentrunbase.h            114 0x7795b5706c79 
8  ??                                                                                                                                                                          0x7795b3ade122 
9  ??                                                                                                                                                                          0x7795b3adaeb1 
10 start_thread                                                                                                                           pthread_create.c                 444 0x7795b3697b5a 
11 clone3                                                                                                                                 clone3.S                         78  0x7795b37285fc                                                                                                                               clone3.S                         78  0x7795b37285fc 
1  QString::operator=(QString const&)                                                                                                                                          0x74f56355f830 
2  nmc::DkMetaDataT::readMetaData                                                                                                         DkMetaData.cpp                   106 0x74f5651d9466 
3  nmc::DkThumbNail::computeIntern                                                                                                        DkThumbs.cpp                     108 0x74f56522ce33 
4  nmc::DkThumbNailT::computeCall                                                                                                         DkThumbs.cpp                     324 0x74f56522e610 
5  operator()                                                                                                                             DkThumbs.cpp                     316 0x74f56522e07c 
6  QtConcurrent::StoredFunctorCall0<QImage, nmc::DkThumbNailT::fetchThumb(int, QSharedPointer<QByteArray>)::<lambda()>>::runFunctor(void) qtconcurrentstoredfunctioncall.h 60  0x74f56522ebc4 
7  QtConcurrent::RunFunctionTask<QImage>::run                                                                                             qtconcurrentrunbase.h            114 0x74f565147c79 
8  ??                                                                                                                                                                          0x74f5634de122 
9  ??                                                                                                                                                                          0x74f5634daeb1 
10 start_thread                                                                                                                           pthread_create.c                 444 0x74f563097b5a 
11 clone3                                                                                                                                 clone3.S                         78  0x74f5631285fc 

This is Linux, git master 6dfc779. I can also confirm on 3.17.2206 Ubuntu package.

@leejuyuu
Copy link
Collaborator

leejuyuu commented Jun 1, 2024

Hello @scrubbbbs, thanks for reporting. Could you provide your system (windows?) and the version of nomacs?

@leejuyuu
Copy link
Collaborator

leejuyuu commented Jun 1, 2024

Could you specify which commit? Something like git master would be ambiguous for future readers.

scrubbbbs added a commit to scrubbbbs/nomacs that referenced this issue Jun 1, 2024
DkThumbNail::computeIntern() was being invoked with a QString reference,
and was also referencing a member variable. Which made it non-reentrant
and led to segfault in Qt string operations.

This is corrected, in addition some refactoring is added to prevent this
from happening again.

- All params to lambda are copies (no "&" or "this" is passed)
- computeIntern() is declared static
- computeCall() has been dropped
novomesk pushed a commit that referenced this issue Jun 1, 2024
DkThumbNail::computeIntern() was being invoked with a QString reference,
and was also referencing a member variable. Which made it non-reentrant
and led to segfault in Qt string operations.

This is corrected, in addition some refactoring is added to prevent this
from happening again.

- All params to lambda are copies (no "&" or "this" is passed)
- computeIntern() is declared static
- computeCall() has been dropped
@leejuyuu
Copy link
Collaborator

leejuyuu commented Jun 2, 2024

@scrubbbbs please add a Fixes <issue link> in the commit or PR body next time so they link to and close issues automatically when merged, thanks.

@leejuyuu
Copy link
Collaborator

leejuyuu commented Jun 2, 2024

Should be fixed by #1085.

@leejuyuu leejuyuu closed this as completed Jun 2, 2024
@scrubbbbs
Copy link
Contributor Author

Thanks, I did not know that was possible.

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