Repository navigation
Segfault with CompImageHDU #9715
Copy link
Copy link
Closed
Description
The following code (sometimes) segfaults on my machine.
import numpy as np
from astropy.io import fits
from io import BytesIO
import faulthandler
faulthandler.enable()
arr = np.array([1,5123124,2,1,2,1]).astype(int)
hdu = fits.CompImageHDU(arr, compression_type="PLIO_1")
buffer = BytesIO()
hdu.writeto(buffer)
print(buffer.getvalue())
buffer.seek(0)
with fits.open(buffer, memmap=False) as hdulist:
print(hdulist)
The faulthandler reports varying stack-traces, for example:
Current thread 0x0000344c (most recent call first):
File "...\lib\site-packages\astropy\io\fits\hdu\compressed.py", line 1663 in _update_compressed_data
File "...\lib\site-packages\astropy\io\fits\hdu\compressed.py", line 1793 in _prewriteto
File "...\lib\site-packages\astropy\io\fits\hdu\hdulist.py", line 935 in writeto
File "...\lib\site-packages\astropy\utils\decorators.py", line 521 in wrapper
File "...\lib\site-packages\astropy\io\fits\hdu\base.py", line 1582 in writeto
File "...\lib\site-packages\astropy\utils\decorators.py", line 521 in wrapper
or
Current thread 0x000000f4 (most recent call first):
File "...\lib\site-packages\astropy\io\fits\util.py", line 674 in _array_to_file_like
File "...\lib\site-packages\astropy\io\fits\util.py", line 651 in _array_to_file
File "...\lib\site-packages\astropy\io\fits\file.py", line 380 in writearray
File "...\lib\site-packages\astropy\io\fits\hdu\table.py", line 931 in _writedata_internal
File "...\lib\site-packages\astropy\io\fits\hdu\base.py", line 610 in _writedata
File "...\lib\site-packages\astropy\io\fits\hdu\compressed.py", line 1839 in _writedata
File "...\lib\site-packages\astropy\io\fits\hdu\base.py", line 680 in _writeto_internal
File "...\lib\site-packages\astropy\io\fits\hdu\base.py", line 674 in _writeto
File "...\lib\site-packages\astropy\io\fits\hdu\hdulist.py", line 936 in writeto
File "...\lib\site-packages\astropy\utils\decorators.py", line 521 in wrapper
File "...\lib\site-packages\astropy\io\fits\hdu\base.py", line 1582 in writeto
File "...\lib\site-packages\astropy\utils\decorators.py", line 521 in wrapper
or
Current thread 0x00002a60 (most recent call first):
File "...\lib\site-packages\astropy\io\fits\column.py", line 1953 in __new__
File "...\lib\site-packages\astropy\io\fits\fitsrec.py", line 782 in _convert_p
File "...\lib\site-packages\astropy\io\fits\fitsrec.py", line 702 in field
File "...\lib\site-packages\astropy\io\fits\hdu\table.py", line 522 in _prewriteto
File "...\lib\site-packages\astropy\io\fits\hdu\compressed.py", line 1821 in _prewriteto
File "...\lib\site-packages\astropy\io\fits\hdu\hdulist.py", line 935 in writeto
File "...\lib\site-packages\astropy\utils\decorators.py", line 521 in wrapper
File "...\lib\site-packages\astropy\io\fits\hdu\base.py", line 1582 in writeto
File "...\lib\site-packages\astropy\utils\decorators.py", line 521 in wrapper
It could be windows-specific as in PR #9641 but could also be something different.
It could be an issue with an upstream dependency like NumPy, cfitsio or even CPython. I wasn't able to get to the root-cause of the issue.
Reactions are currently unavailable
Activity
[-]Segfault with BinTableHDU[/-][+]Segfault with CompImageHDU[/+]MSeifert04 commentedon Dec 3, 2019
On further inspection this probably isn't related to #9641 because it doesn't fail for non-PLIO compressions. 🤷♂
MSeifert04 commentedon Dec 3, 2019
@pllim Given the label I assume you tested it on a non-windows machine? Did it always work correctly there - even when executed multiple times in a row?
pllim commentedon Dec 3, 2019
Oh, I just assumed since this was first mentioned in #9641 that dealt with Windows specific segfault. Sorry!
MSeifert04 commentedon Dec 3, 2019
Well, it could be windows-specific but I haven't had time to run it in docker 😄
MSeifert04 commentedon Dec 3, 2019
In my linux docker environment with python&numpy debug:
So probably not windows-specific.
pllim commentedon Dec 3, 2019
MSeifert04 commentedon Dec 3, 2019
Or inside CFITSIO 🤷♂
pllim commentedon Dec 3, 2019
Thanks for checking, @MSeifert04 !
MSeifert04 commentedon Dec 4, 2019
I think the error happens during the call to
fits_write_img(fileptr, datatype, 1, PyArray_SIZE(indata), PyArray_DATA(indata), &status);. At least that's what my print-debugging indicates 😓pllim commentedon Dec 4, 2019
So it is
cfitsio. 😞MSeifert04 commentedon Dec 4, 2019
Or we're passing invalid parameters... I really hate C debugging in docker 😟
saimn commentedon Dec 13, 2019
I get this with your code, which probably means that some type detection is not done correctly on all platforms ?
saimn commentedon Dec 13, 2019
Or you are using a 32bits system ?
saimn commentedon Dec 13, 2019
So I can reproduce with int32 data:
The crash happens here (in cfitsio):
pllim commentedon Dec 13, 2019
So is this bug still in
cfitsioor inastropy.io.fits?Cadair commentedon Dec 15, 2022
for what it's worth at this point (when we are going to fix it in a soon-to-be opened pr), but this is a bug in
astropy.io.fits.