I was trying to run my script and got this output:

orig file has 104424 rows and 161190 cols total
('window (row_start, row_stop), (col_start, col_stop)', ((55150, 72608), (13802, 31386)))
./my_script: line 3: 20326 Segmentation fault      (core dumped) python -O my_main_functions.py $*

I ran through with pdb and found that the segfault was happening on my call to rasterio.open:

with rasterio.open(orig_data_file) as f:
    data = f.read(1, window=window)

The window was valid. I thought it might be a memory error, so in my debug session I tried doing so with a window of ((55150, 55151), (13802, 13803)) but I still got the segfault.

Why would rasterio segfault trying to read a tiny, valid window?


For some reason, rasterio trips up on reading a symlink!!!

I had another test function that was calling this very code using orig_data_file=/my/original/datafile.img
which worked fine without any errors.

My code with the segfault was using

/my/symlink/to/same/datafile.img -> /my/original/datafile.img

So I added

orig_data_file = os.path.realpath( orig_data_file )

at the beginning of my script and it worked!

I don't know why rasterio didn't trip up reading my symlink in this code:

with rasterio.open(orig_data_file) as f:
    profile = f.profile
    crs = profile['crs']
    orig_proj_str = crs.to_string()
    orig_affine = profile['affine']
    orig_num_rows = f.height
    orig_num_cols = f.width

But for the

with rasterio.open(orig_data_file) as f:
    data = f.read(1, window=window)

it segfaults if the file is really a symlink! Gah!

  • I have no trouble using rasterio (v1.0a12) to open and read symlinked files on recent Ubuntu versions. It would be useful if you could edit your question to specify what OS and rasterio version you are using and how you installed rasterio. – user2856 Apr 19 '18 at 3:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.