Commit 4b18460b authored by Max Kellermann's avatar Max Kellermann

archive/bz2: unlock the archive mutex and lock the file mutex

Fixes deadlock because FileInputStream::Read() unlocks the mutex (which was not locked) and then locks it, keeping it locked. This can result in a deadlock. This happens because the archive and the file mutex are different.
parent 412c0a96
ver 0.20.14 (not yet released) ver 0.20.14 (not yet released)
* database * database
- simple: fix file corruption in the presence of mount points - simple: fix file corruption in the presence of mount points
* archive
- bz2: fix deadlock
* fix Solaris build failure * fix Solaris build failure
ver 0.20.13 (2017/12/18) ver 0.20.13 (2017/12/18)
......
...@@ -162,7 +162,7 @@ Bzip2InputStream::FillBuffer() ...@@ -162,7 +162,7 @@ Bzip2InputStream::FillBuffer()
if (bzstream.avail_in > 0) if (bzstream.avail_in > 0)
return true; return true;
size_t count = archive->istream->Read(buffer, sizeof(buffer)); size_t count = archive->istream->LockRead(buffer, sizeof(buffer));
if (count == 0) if (count == 0)
return false; return false;
...@@ -174,6 +174,8 @@ Bzip2InputStream::FillBuffer() ...@@ -174,6 +174,8 @@ Bzip2InputStream::FillBuffer()
size_t size_t
Bzip2InputStream::Read(void *ptr, size_t length) Bzip2InputStream::Read(void *ptr, size_t length)
{ {
const ScopeUnlock unlock(mutex);
int bz_result; int bz_result;
size_t nbytes = 0; size_t nbytes = 0;
...@@ -224,4 +226,3 @@ const ArchivePlugin bz2_archive_plugin = { ...@@ -224,4 +226,3 @@ const ArchivePlugin bz2_archive_plugin = {
bz2_open, bz2_open,
bz2_extensions, bz2_extensions,
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment