Skip to content

Use borrowed data when exporting an image created by Image.fromarrow - #9897

Open
lazerg wants to merge 3 commits into
python-pillow:mainfrom
lazerg:fix/issue-9896-arrow-borrowed-export
Open

Use borrowed data when exporting an image created by Image.fromarrow#9897
lazerg wants to merge 3 commits into
python-pillow:mainfrom
lazerg:fix/issue-9896-arrow-borrowed-export

Conversation

@lazerg

@lazerg lazerg commented Aug 24, 2026

Copy link
Copy Markdown

Resolves #9896

An image created by Image.fromarrow() borrows its data, so block and blocks are both NULL and only the row pointers in image are set. export_single_channel_array() and export_fixed_pixel_array() fall back to blocks[0].ptr when block is NULL, which dereferenced NULL and crashed on pa.array(im).

A borrowed array is only accepted when its length matches the image, so the rows are contiguous and the export can start from the first one.

@radarhere

Copy link
Copy Markdown
Member

I've created lazerg#1 with a suggestion.

@lazerg

lazerg commented Aug 29, 2026

Copy link
Copy Markdown
Author

Good catch, thanks. RGBX/CMYK/YCbCr/HSV route through the same export_fixed_pixel_array path as RGBA (branch is picked purely by im->bands == 1, not by mode), so the fix covers them too. Applied your refactor and ran all 10 modes locally: all pass, including the 4 new ones. Pushed as bd55c41.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exporting an image created by Image.fromarrow with __arrow_c_array__ crashes with a segmentation fault

2 participants