Skip to content

Fix multipart upload parsing edge cases#22

Merged
freelamb merged 1 commit into
masterfrom
codex/analyze-and-resolve-issues
Jun 3, 2026
Merged

Fix multipart upload parsing edge cases#22
freelamb merged 1 commit into
masterfrom
codex/analyze-and-resolve-issues

Conversation

@freelamb

@freelamb freelamb commented Jun 3, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Harden multipart POST handling to correctly parse variable part headers and avoid assumptions about optional headers.
  • Prevent truncation when uploaded content contains boundary-like text and ensure interrupted or malformed uploads do not leave partial files on disk.
  • Add targeted unit tests for upload parsing regressions and record a bugfix release.

Description

  • Replace the brittle header-reading logic in deal_post_data() with a loop that reads part headers until the blank separator and extracts the filename from combined headers, using helper functions read_upload_line() and is_boundary_line() to robustly detect boundaries.
  • Add validation to reject negative Content-Length values and ensure the upload target from translate_path() is an existing directory before writing the file.
  • Preserve uploaded content that omits an optional part Content-Type header and avoid treating content that merely contains boundary-like text as a delimiter by matching only full boundary delimiter lines.
  • Ensure partial files are removed on failure by deleting the incomplete target_path when the upload does not complete successfully, and bump __version__ to 0.3.4 and update CHANGELOG.md accordingly.
  • Add new tests in tests/test_simple_http_server.py (UploadParsingTests) and a DummyUploadHandler to cover: missing part Content-Type, content containing boundary-like text, and interrupted uploads leaving no partial file.

Testing

  • Ran python3 -m py_compile simple_http_server.py successfully.
  • Ran python3 -m unittest discover -s tests and all tests passed (8 tests ran, OK).
  • Attempted flake8 checks but flake8 is not installed in the environment, so those checks were not executed.

Codex Task

@freelamb freelamb merged commit fc4ebea into master Jun 3, 2026
3 checks passed
@freelamb freelamb deleted the codex/analyze-and-resolve-issues branch June 3, 2026 04:25
@freelamb

freelamb commented Jun 3, 2026

Copy link
Copy Markdown
Owner Author

issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant