Skip to content

(AwsS3): TypeError when writing a resource with aws-sdk-php >= 3.383.1" #728

Description

@GertjanVandenKeybus

Error:
/src/Gaufrette/Adapter/AwsS3.php
mb_strlen(): Argument #1 ($string) must be of type string, resource given

What I think is happening:
AwsS3Adapter::write() computes the returned byte count from $content after putObject(). Since aws-sdk-php 3.383.1 (which fixed per-request cyclic references in its middleware), the SDK closes a resource body once the request completes. A closed resource fails is_resource(), so execution falls through to Util\Size::fromContent() and crashes with mb_strlen(): Argument #1 ($string) must be of type string, resource given. Being a TypeError, it also bypasses the method's catch (\Exception).
Before 3.383.1 this worked only because the SDK leaked a reference that kept the stream open. Bisected: open through 3.383.0, closed from 3.383.1, independent of guzzle 6/7 and psr7 1/2.
Fix: compute the size before calling putObject(). The resource is still open at that point, so Size::fromResource() (fstat) returns the correct full file size. No behavior change for string content.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions