Opened 9 years ago

Closed 9 years ago

#5938 closed defect (fixed)

Segmentation fault when combining vsimem with vsigzip

Reported by: dsogari Owned by: warmerdam
Priority: normal Milestone:
Component: default Version: svn-trunk
Severity: normal Keywords: segfault; vsimem; vsigzip
Cc:

Description

Hi,

I found a problem with the VSIFCloseL function when using the memory filesystem driver in composition with the gzip driver. The problem is that if I open a gzip archive located under /vsimem, then "accidentally" delete the archive through /vsimem, and then try to close it, I get segmentation fault.

Looking at the code in VSIGZipFilesystemHandler::SaveInfo method I found that, at the end, it calls VSIGZipHandle::Duplicate to get a new handle. Only, it does not verify that the returned object is non NULL. So if it is, then the call to CloseBaseHandle produces segmentation fault.

Surely this is a very uncommon use case. Nonetheless, for the sake of robustness, I propose the following alteration.

in gdal/port/cpl_vsi_gzip.cpp [my local copy is in 28977]

method VSIGZipFilesystemHandler::SaveInfo, line 1327:

        poHandleLastGZipFile->CloseBaseHandle();

replace by:

        if (poHandleLastGZipFile)
            poHandleLastGZipFile->CloseBaseHandle();

Please let me know if you find other issues with this solution.

Regards.

Change History (1)

comment:1 by Even Rouault, 9 years ago

Resolution: fixed
Status: newclosed

trunk r29033 "VSIGZipFilesystemHandler::SaveInfo_unlocked(): add check to avoid segfault in some rare circumstances (patch by dsogari, #5938)"

Note: See TracTickets for help on using tickets.