Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential bug in stream conversion #35

Open
Xerkus opened this issue Apr 18, 2023 · 0 comments
Open

Potential bug in stream conversion #35

Xerkus opened this issue Apr 18, 2023 · 0 comments
Labels
Bug Something isn't working

Comments

@Xerkus
Copy link
Member

Xerkus commented Apr 18, 2023

Bug Report

Q A
Version(s) 1.9.0

Summary

Conversion of stream resource from PSR-7 response to Laminas response assumes PSR-7 resource is a stream that can be reopened with fopen using metadata url. This assumption will work in most common cases but can have significant side effects otherwise.

Conversion implementation breaks encapsulation and violates PSR-7 contract. Just looking at current Diactoros, it would break when Stream object holds a non-stream resource, resource is not rewindable and/or rewindable with Stream internal read cache, for RelativeStream, and when Stream holds a network socket in pass-through scenario.

All body/stream conversions are suspect and warrant a closer look.

I think the only sensible solution here is to always read StreamInterface object in chunks and write to php://temp stream. This would potentially create significant performance overhead.

Current behavior

$uri = $psr7Response->getBody()->getMetadata('uri');

$response->setStream(fopen($uri, 'rb'));

How to reproduce

Expected behavior

Any StreamInterface implementation is safely copied.

@Xerkus Xerkus added the Bug Something isn't working label Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant