Skip to content

Potential bug in stream conversion #35

@Xerkus

Description

@Xerkus

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions