Description

When the MaxMultipartMemory parameter is very large, the maxValueBytes+1 will overflows.

// Reserve an additional 10 MB for non-file parts.
maxValueBytes := maxMemory + int64(10<<20)
if maxValueBytes <= 0 {
    if maxMemory < 0 {
        maxValueBytes = 0
    } else {
        maxValueBytes = math.MaxInt64
    }
}

if filename == "" {
    // value, store as string in memory
    n, err := io.CopyN(&b, p, maxValueBytes+1)
    if err != nil && err != io.EOF {
        return nil, err
    }
    maxValueBytes -= n
    if maxValueBytes < 0 {
        return nil, ErrMessageTooLarge
    }
    form.Value[name] = append(form.Value[name], b.String())
    continue
}

Expectations

The maxValueBytes maximum value can be set to math.MaxInt64-1.

// Reserve an additional 10 MB for non-file parts.
maxValueBytes := maxMemory + int64(10<<20)
if maxValueBytes <= 0 {
    if maxMemory < 0 {
        maxValueBytes = 0
    } else {
        maxValueBytes = math.MaxInt64 - 1
    }
}

Environment

  • go version: 1.16
  • gin version (or commit ref): v1.7.7
  • operating system: windows 10