Skip to content

fix: boundary parser error (error parsing multipart NextPart: bufio: buffer full) - #2235

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/boundary-parser-error
Nov 16, 2025
Merged

fix: boundary parser error (error parsing multipart NextPart: bufio: buffer full)#2235
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
seefs001:fix/boundary-parser-error

Conversation

@seefs001

@seefs001 seefs001 commented Nov 16, 2025

Copy link
Copy Markdown
Collaborator

fix #2234
解析 boundary方法不规范

Summary by CodeRabbit

  • Bug Fixes

    • Improved multipart form parsing with robust boundary detection and comprehensive error handling for more reliable file uploads.
    • Made form submission memory limits configurable, replacing the previously fixed 32 MB constraint to better accommodate varying resource requirements.
  • Refactor

    • Streamlined memory management for form data processing with consistent limit application across all parsing operations.

@coderabbitai

coderabbitai Bot commented Nov 16, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes implement robust multipart form boundary extraction using mime.ParseMediaType and introduce a configurable memory limit for form parsing, replacing fixed 32 MB buffers and ad-hoc boundary extraction logic. Error handling for missing boundaries includes fallback behavior in multipart form data parsing.

Changes

Cohort / File(s) Summary
Multipart Form Parsing Enhancement
common/gin.go
Adds parseBoundary() function for robust boundary extraction via mime.ParseMediaType; introduces errBoundaryNotFound error sentinel; replaces fixed 32 MB memory limit with configurable multipartMemoryLimit() function derived from constant.MaxFileDownloadMB; updates ParseMultipartFormReusable() and parseMultipartFormData() to use new boundary extraction and memory limit logic; adds fallback to Unmarshal when boundary is missing; imports errors and mime packages

Sequence Diagram

sequenceDiagram
    participant Client
    participant Handler as Gin Handler
    participant Parser as Parser Logic
    participant ParseBoundary as parseBoundary()
    participant ReadForm as ReadForm
    participant Unmarshal as Unmarshal Fallback

    Client->>Handler: Multipart Request
    Handler->>Parser: parseMultipartFormData()
    
    Parser->>ParseBoundary: contentType
    alt Boundary Found
        ParseBoundary-->>Parser: boundary value
        Parser->>ReadForm: ReadForm(bytes, multipartMemoryLimit())
        ReadForm-->>Parser: form data
        Parser-->>Handler: parsed form
    else Boundary Not Found
        ParseBoundary-->>Parser: errBoundaryNotFound
        Parser->>Unmarshal: fallback deserialization
        Unmarshal-->>Parser: form data
        Parser-->>Handler: fallback result
    end
    
    Handler-->>Client: Response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Single file modified with focused, cohesive changes
  • New helper functions are straightforward (boundary extraction, memory limit calculation)
  • Clear error handling with documented fallback behavior
  • Particular attention needed on:
    • Fallback logic correctness when boundary is missing
    • Memory limit configuration defaults and safety bounds
    • Compatibility with existing multipart parsing downstream

Poem

🐰 A boundary once lost in the bytes,
Now parsed with mime and its lights,
With configurable memory to spare,
Form data flows without a care—
Buffer overflow? Not today, dear friend! ✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: fixing the boundary parser error that causes 'bufio: buffer full' errors in multipart parsing.
Linked Issues check ✅ Passed The code changes directly address issue #2234 by implementing robust boundary extraction and configurable memory limits for multipart parsing to resolve the buffer full error.
Out of Scope Changes check ✅ Passed All changes are scoped to multipart form parsing in common/gin.go and directly support fixing the boundary parser error reported in issue #2234.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e07347a and e169818.

📒 Files selected for processing (1)
  • common/gin.go (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
common/gin.go (2)
common/json.go (1)
  • Unmarshal (9-11)
constant/env.go (1)
  • MaxFileDownloadMB (5-5)
🔇 Additional comments (6)
common/gin.go (6)

5-7: LGTM!

The added imports (errors and mime) are standard library packages required for the new boundary parsing and error handling logic.


133-139: Good refactor to use standard boundary parsing.

The changes correctly use parseBoundary for robust boundary extraction and apply the configurable memory limit. The direct error return (no fallback) is appropriate for a multipart-specific function.


182-191: Robust error handling with JSON fallback.

The boundary parsing is now standard-compliant, and the fallback to JSON when boundary is missing (lines 184-186) provides resilience for edge cases. The configurable memory limit is applied correctly.


208-208: LGTM!

Using a sentinel error for missing boundary is idiomatic Go and enables precise error handling with errors.Is.


210-225: Excellent fix - this addresses the root cause.

Using mime.ParseMediaType is the standard-compliant way to extract the boundary parameter from Content-Type headers. This replaces the non-standard parsing method mentioned in the PR and should resolve the multipart parsing errors.


227-234: No issues identified; configuration is appropriate.

The code correctly converts MB to bytes using bit shift (<<20), and the multipart memory limit is properly configured. The environment default is 20 MB with a 32 MB fallback when unconfigured, which aligns with audio file upload limits (OpenAI's API accepts up to 25 MB audio files). The value is environment-configurable via MAX_FILE_DOWNLOAD_MB.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Calcium-Ion
Calcium-Ion merged commit 2b4617d into QuantumNous:main Nov 16, 2025
1 check passed
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
…-error

fix: boundary parser error (error parsing multipart NextPart: bufio: buffer full)
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
…-error

fix: boundary parser error (error parsing multipart NextPart: bufio: buffer full)
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 this pull request may close these issues.

调用 /v1/audio/transcriptions 接口报错

2 participants