https://bugs.kde.org/show_bug.cgi?id=526851

            Bug ID: 526851
           Summary: libzip plugin ignores the return value of zip_close(),
                    so failed writes are reported as success
    Classification: Applications
           Product: ark
      Version First 26.08.1
       Reported In:
          Platform: Other
                OS: Linux
            Status: REPORTED
          Severity: normal
          Priority: NOR
         Component: plugins
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
  Target Milestone: ---

STEPS TO REPRODUCE

    ark --batch --add-to /tmp/does-not-exist/a.zip some-file.txt

OBSERVED RESULT

Ark exits with status 0 and logs:

    Failed to open archive. Code: 9
    Job finished, result: true , time: 1 ms

No archive exists. An LD_PRELOAD shim around libzip shows that zip_close()
failed with "Failure to create temporary file: No such file or directory".

EXPECTED RESULT

The job fails and shows libzip's error message.

CAUSE

plugins/libzipplugin/libzipplugin.cpp, in addFiles, deleteFiles, addComment,
moveFiles and copyFiles (release/26.08 lines 345, 616, 648, 1033, 1122; master
is the same):

    zip_close(archive.get());
    archive.release();
    if (errcode > 0) {
        qCCritical(ARK_LOG) << "Failed to write archive";

errcode is the result of the earlier zip_open() and is 0 here, so a failing
zip_close() is never detected. libzip removes its temporary file, and the
follow-up listing fails with code 9 (no such file). When zip_close() fails it
also does not free the zip_t, so archive.release() leaks it.

SUGGESTED FIX

The unique_ptr already has zip_discard as deleter, so release it only on
success:

    if (zip_close(archive.get()) != 0) {
        qCCritical(ARK_LOG) << "Failed to write archive:" <<
zip_strerror(archive.get());
        Q_EMIT error(xi18n("Failed to write archive: %1",
QString::fromUtf8(zip_strerror(archive.get()))));
        return false; // the deleter calls zip_discard()
    }
    archive.release(); // zip_close() freed the archive

RELATED

Every error inside zip_close() takes this path. An unreadable source file makes
zip_close() fail with "Can't open file: Permission denied" (checked with libzip
1.11.4), which is probably the zip part of bug 452640 (comment 1: ".zip will
fail to produce a file at all, no errors"). Bug 505628 (non-existent
destination folder, "Finished" notification) matches the steps above if zip was
used there.

SOFTWARE/OS VERSIONS

Arch Linux, KDE Plasma 6.7.5, KDE Frameworks 6.30.0, Qt 6.11.2, Ark 26.08.1,
libzip 1.11.4

ADDITIONAL INFORMATION

Drafted with an AI assistant (Claude) from source reading and tests on the
reporter's system.

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to