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

Cannot upload empty file or blank file field #2778

Closed
sshymko opened this issue Aug 26, 2019 · 1 comment · Fixed by #2779
Closed

Cannot upload empty file or blank file field #2778

sshymko opened this issue Aug 26, 2019 · 1 comment · Fixed by #2779

Comments

@sshymko
Copy link
Contributor

sshymko commented Aug 26, 2019

Preconditions:

  • Swoole 4.x (any version)

Steps to reproduce:

  1. Create a simple Swoole server that responds with uploaded files:
    $server = new \Swoole\Http\Server('127.0.0.1', 8180);
    $server->on('request', function ($request, $response) {
        $response->header('Content-Type', 'text/plain');
        $response->end(var_export($request->files, true));
    });
    $server->start();
  2. Create simple HTML form with file upload fields, for example:
    <!DOCTYPE html>
    <html>
    <body>
        <form action="http://127.0.0.1:8180/" method="post" enctype="multipart/form-data">
            <input type="file" name="file1"><br>
            <input type="file" name="file2"><br>
            <input type="file" name="file3"><br>
            <input type="submit" value="Upload">
        </form>
    </body>
    </html>
  3. Open the file upload form in a browser
  4. Select non-empty file for field file1
  5. Select empty file for field file2
  6. Leave blank value for field file3
  7. Submit the form

Alternative steps to reproduce:

  1. Upload files form data:
    curl http://127.0.0.1:8180/ \
        -F 'file1=@shipping_rates.csv;type=text/csv' \
        -F 'file2=@/dev/null;filename=empty.txt;type=text/plain' \
        -F 'file3=@/dev/null;filename=' \

Expected result:

  • Non-empty file has been uploaded successfully
  • Empty file has been uploaded successfully with zero size
  • Blank file field has empty upload metadata temp filename and MIME type
    array (
      'file1' => 
      array (
        'name' => 'shipping_rates.csv',
        'type' => 'text/csv',
        'tmp_name' => '/tmp/swoole.upfile.NxKEmB',
        'error' => 0,
        'size' => 2469,
      ),
      'file2' => 
      array (
        'name' => 'empty.txt',
        'type' => 'text/plain',
        'tmp_name' => '/tmp/swoole.upfile.hllJL5',
        'error' => 0,
        'size' => 0,
      ),
      'file3' => 
      array (
        'name' => '',
        'type' => '',
        'tmp_name' => '',
        'error' => 4,
        'size' => 0,
      ),
    )

Actual result:

  • Non-empty file has been uploaded successfully
  • Empty file has been uploaded with error HTTP_UPLOAD_ERR_NO_FILE = 4
  • Blank file field has irrelevant temp filename and MIME type metadata
    array (
      'file1' => 
      array (
        'name' => 'shipping_rates.csv',
        'type' => 'text/csv',
        'tmp_name' => '/tmp/swoole.upfile.NxKEmB',
        'error' => 0,
        'size' => 2469,
      ),
      'file2' => 
      array (
        'name' => 'empty.txt',
        'type' => 'text/plain',
        'tmp_name' => '/tmp/swoole.upfile.hllJL5',
        'error' => 4,
        'size' => 0,
      ),
      'file3' => 
      array (
        'name' => '',
        'type' => 'application/octet-stream',
        'tmp_name' => '/tmp/swoole.upfile.Gv03qi',
        'error' => 4,
        'size' => 0,
      ),
    )
@sshymko
Copy link
Contributor Author

sshymko commented Aug 26, 2019

This issue is related to #2743 identifying data structure differences with $_FILES.

@sshymko sshymko changed the title Request object contains irrelevant metadata for empty file upload Irrelevant metadata for empty file upload Aug 26, 2019
@sshymko sshymko changed the title Irrelevant metadata for empty file upload Irrelevant metadata for blank file upload field Aug 26, 2019
sshymko added a commit to upscalesoftware/swoole-src that referenced this issue Aug 26, 2019
- Distinguish blank file field from empty file contents
- Prevent empty temp file creation for blank file field
- Remove irrelevant MIME type of blank file field
- Resolve swoole#2778 Irrelevant metadata for blank file upload field
sshymko added a commit to upscalesoftware/swoole-src that referenced this issue Aug 26, 2019
- Distinguish blank file field from empty file contents
- Fix inability to upload empty file of zero size
- Prevent empty temp file creation for blank file field
- Remove irrelevant MIME type of blank file field
- Resolve swoole#2778 Irrelevant metadata for blank file upload field
sshymko added a commit to upscalesoftware/swoole-src that referenced this issue Aug 26, 2019
- Distinguish blank file field from empty file contents
- Fix inability to upload empty file of zero size
- Prevent empty temp file creation for blank file field
- Remove irrelevant MIME type of blank file field
- Resolve swoole#2778 Irrelevant metadata for blank file upload field
sshymko added a commit to upscalesoftware/swoole-src that referenced this issue Aug 26, 2019
- Cover upload of empty file of zero size with tests
- Cover form submission of blank file field with tests
- Resolve swoole#2778 Irrelevant metadata for blank file upload field
sshymko added a commit to upscalesoftware/swoole-src that referenced this issue Aug 26, 2019
- Cover upload of empty file of zero size with tests
- Cover form submission of blank file field with tests
- Resolve swoole#2778 Irrelevant metadata for blank file upload field
sshymko added a commit to upscalesoftware/swoole-src that referenced this issue Aug 26, 2019
- Cover upload of empty file of zero size with tests
- Cover form submission of blank file field with tests
- Resolve swoole#2778 Irrelevant metadata for blank file upload field
sshymko added a commit to upscalesoftware/swoole-src that referenced this issue Aug 26, 2019
- Cover upload of empty file of zero size with tests
- Cover form submission of blank file field with tests
- Resolve swoole#2778 Irrelevant metadata for blank file upload field
sshymko added a commit to upscalesoftware/swoole-src that referenced this issue Aug 26, 2019
- Fix emulation of blank file field upload
- Replace cURL file upload with socket communication
- Resolve swoole#2778 Irrelevant metadata for blank file upload field
@sshymko sshymko changed the title Irrelevant metadata for blank file upload field Cannot upload empty file or blank file field Aug 26, 2019
sshymko added a commit to upscalesoftware/swoole-src that referenced this issue Aug 26, 2019
- Distinguish blank file field from empty file contents
- Fix inability to upload empty file of zero size
- Prevent empty temp file creation for blank file field
- Remove irrelevant MIME type of blank file field
- Resolve swoole#2778 Cannot upload empty file or blank file field
sshymko added a commit to upscalesoftware/swoole-src that referenced this issue Aug 26, 2019
- Cover upload of empty file of zero size with tests
- Cover form submission of blank file field with tests
- Resolve swoole#2778 Cannot upload empty file or blank file field
sshymko added a commit to upscalesoftware/swoole-src that referenced this issue Aug 26, 2019
- Fix emulation of blank file field upload
- Replace cURL file uploader with raw socket
- Resolve swoole#2778 Cannot upload empty file or blank file field
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant