mirror of
https://codeberg.org/git-pages/git-pages.git
synced 2026-06-10 13:30:49 +00:00
Return 422 Unprocessable Entity on invalid archive uploads.
Fixes: https://codeberg.org/git-pages/git-pages/issues/216
This commit is contained in:
@@ -244,3 +244,41 @@ func ExtractZip(ctx context.Context, reader io.Reader, oldManifest *Manifest) (*
|
||||
|
||||
return manifest, nil
|
||||
}
|
||||
|
||||
func IsArchiveParseError(err error) bool {
|
||||
targets := []error{
|
||||
tar.ErrHeader,
|
||||
tar.ErrWriteTooLong,
|
||||
tar.ErrFieldTooLong,
|
||||
tar.ErrWriteAfterClose,
|
||||
tar.ErrInsecurePath,
|
||||
|
||||
zip.ErrFormat,
|
||||
zip.ErrAlgorithm,
|
||||
zip.ErrChecksum,
|
||||
zip.ErrInsecurePath,
|
||||
|
||||
gzip.ErrChecksum,
|
||||
gzip.ErrHeader,
|
||||
|
||||
zstd.ErrReservedBlockType,
|
||||
zstd.ErrCompressedSizeTooBig,
|
||||
zstd.ErrBlockTooSmall,
|
||||
zstd.ErrUnexpectedBlockSize,
|
||||
zstd.ErrMagicMismatch,
|
||||
zstd.ErrWindowSizeExceeded,
|
||||
zstd.ErrWindowSizeTooSmall,
|
||||
zstd.ErrDecoderSizeExceeded,
|
||||
zstd.ErrUnknownDictionary,
|
||||
zstd.ErrFrameSizeExceeded,
|
||||
zstd.ErrFrameSizeMismatch,
|
||||
zstd.ErrCRCMismatch,
|
||||
}
|
||||
|
||||
for _, target := range targets {
|
||||
if errors.Is(err, target) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -712,6 +712,8 @@ func reportUpdateResult(w http.ResponseWriter, r *http.Request, result UpdateRes
|
||||
w.WriteHeader(http.StatusUnsupportedMediaType)
|
||||
} else if errors.Is(result.err, ErrArchiveTooLarge) {
|
||||
w.WriteHeader(http.StatusRequestEntityTooLarge)
|
||||
} else if IsArchiveParseError(result.err) {
|
||||
w.WriteHeader(http.StatusUnprocessableEntity)
|
||||
} else if errors.Is(result.err, ErrRepositoryTooLarge) {
|
||||
w.WriteHeader(http.StatusUnprocessableEntity)
|
||||
} else if errors.Is(result.err, ErrMalformedPatch) {
|
||||
|
||||
Reference in New Issue
Block a user