8000 [Mime] TextPart does not check for file path · Issue #57258 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Mime] TextPart does not check for file path #57258

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

Closed
Neirda24 opened this issue May 31, 2024 · 1 comment
Closed

[Mime] TextPart does not check for file path #57258

Neirda24 opened this issue May 31, 2024 · 1 comment

Comments

@Neirda24
Copy link
Contributor

Symfony version(s) affected

All current versions

Description

When using DataPartFile with a wrong path (file does not exists) and then calling ->getBody() it returns an empty string instead of an error.

How to reproduce

(new DataPartFile('/some/wrong/path/to/file.md'))->getBody() === ''; // true.

Possible Solution

It is because Symfony does not use strict types. When calling file_get_contents in this code :

public function getBody(): string
    {
        if ($this->body instanceof File) {
            return file_get_contents($this->body->getPath());
        }

        if (null === $this->seekable) {
            return $this->body;
        }

        if ($this->seekable) {
            rewind($this->body);
        }

        return stream_get_contents($this->body) ?: '';
    }

It automatically converts the false to ''.

Maybe wirth checking if false then throw throw new InvalidArgumentException(sprintf('Path "%s" is not readable.', $path)); like in __construct.

Additional Context

No response

@fabpot
Copy link
Member
fabpot commented Jun 1, 2024

See #57284

@fabpot fabpot closed this as completed Jun 2, 2024
fabpot added a commit that referenced this issue Jun 2, 2024
This PR was merged into the 6.4 branch.

Discussion
----------

[Mime] Fix TextPart using an unknown File

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Issues        | Fix #57258 <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead -->
| License       | MIT

Commits
-------

a6c8963 [Mime] Fix TextPart using an unknown File
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
0