Skip to content

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

Merged
radarhere merged 7 commits into
python-pillow:mainfrom
lazerg:fix/issue-9896-arrow-borrowed-export
Sep 23, 2026
Merged

radarhere merged 7 commits into
python-pillow:mainfrom
lazerg:fix/issue-9896-arrow-borrowed-export

Conversation

@lazerg

@lazerg lazerg commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

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
Contributor 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.

@radarhere

Copy link
Copy Markdown
Member

I've created lazerg#2 with a suggestion.

@lazerg

lazerg commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, merged this in (46e5115).

@radarhere

Copy link
Copy Markdown
Member

Could you explain to me the purpose of test_fromarray_interleaved_to_array()? It seems that test_fromarray_to_array() already prevents regression.

@lazerg

lazerg commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Correct.. I removed it in a69acca.

I checked before deleting: with the fix reverted, test_fromarray_to_array still segfaults on its own. The interleaved import shape stays covered by the UINT rows of test_fromarray.

@radarhere
radarhere enabled auto-merge (squash) September 23, 2026 03:32
@radarhere
radarhere merged commit 9ed5ac9 into python-pillow:main Sep 23, 2026
56 checks passed
@aclark4life aclark4life added the Arrow Apache Arrow support (fromarrow, __arrow_c_array__) label Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arrow Apache Arrow support (fromarrow, __arrow_c_array__)

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

4 participants