mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-02 13:44:16 +09:00
Backport https://github.com/go-gitea/gitea/pull/39942 Several handlers and parsers skipped checks that their siblings already perform. - Reject issue, comment, label, milestone and release mutations in archived repositories via the API with one guard per route group, matching the web UI - Hide timeline references and dependencies pointing at issues the doer cannot read, in the web UI and the API, including pull requests of the same repository without pull request access - Reject workflow runs with more than `MaxJobNumPerRun` jobs, including inline reusable workflow jobs, and show rejected pushes as invalid workflow runs - Bound how much of a Helm chart archive is inflated while looking for `Chart.yaml` `release/v28` lacks two helpers this needs, so they are included: `insertInvalidWorkflowRun`, split out of `handleInvalidWorkflows` by https://github.com/go-gitea/gitea/pull/39480, and `packages.NewLimitedReader` from https://github.com/go-gitea/gitea/pull/39366. Co-authored-by: bircni <bircni@icloud.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
18 files changed
+298
-136
No files matched your search
@@ -10,6 +10,7 @@ import (
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"gitea.dev/modules/packages"
|
||||
"gitea.dev/modules/util"
|
||||
"gitea.dev/modules/validation"
|
||||
|
||||
@@ -69,6 +70,8 @@ type Dependency struct {
|
||||
Alias string `json:"alias,omitempty" yaml:"alias,omitempty"`
|
||||
}
|
||||
|
||||
const maxArchiveSize = 256 * 1024 * 1024 // tar members are inflated while looking for Chart.yaml
|
||||
|
||||
// ParseChartArchive parses the metadata of a Helm archive
|
||||
func ParseChartArchive(r io.Reader) (*Metadata, error) {
|
||||
gzr, err := gzip.NewReader(r)
|
||||
@@ -77,7 +80,7 @@ func ParseChartArchive(r io.Reader) (*Metadata, error) {
|
||||
}
|
||||
defer gzr.Close()
|
||||
|
||||
tr := tar.NewReader(gzr)
|
||||
tr := tar.NewReader(packages.NewLimitedReader(gzr, maxArchiveSize))
|
||||
for {
|
||||
hd, err := tr.Next()
|
||||
if err == io.EOF {
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package packages
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"gitea.dev/modules/util"
|
||||
)
|
||||
|
||||
var ErrContentTooLarge = util.NewInvalidArgumentErrorf("content exceeds the size limit")
|
||||
|
||||
type limitedReader struct {
|
||||
io.LimitedReader
|
||||
}
|
||||
|
||||
// NewLimitedReader returns a reader that fails with ErrContentTooLarge once it reads a byte past limit
|
||||
func NewLimitedReader(r io.Reader, limit int64) io.Reader {
|
||||
return &limitedReader{io.LimitedReader{R: r, N: limit + 1}}
|
||||
}
|
||||
|
||||
func (l *limitedReader) Read(p []byte) (int, error) {
|
||||
n, err := l.LimitedReader.Read(p)
|
||||
if l.N == 0 {
|
||||
return max(n-1, 0), ErrContentTooLarge
|
||||
}
|
||||
return n, err
|
||||
}
|
||||
Reference in new issue
Block a user