mirror of
https://github.com/go-gitea/gitea
synced 2024-11-14 14:01:34 +01:00
684b7a999f
* Dump: Use mholt/archive/v3 to support tar including many compressions Signed-off-by: Philipp Homann <homann.philipp@googlemail.com> * Dump: Allow dump output to stdout Signed-off-by: Philipp Homann <homann.philipp@googlemail.com> * Dump: Fixed bug present since #6677 where SessionConfig.Provider is never "file" Signed-off-by: Philipp Homann <homann.philipp@googlemail.com> * Dump: never pack RepoRootPath, LFS.ContentPath and LogRootPath when they are below AppDataPath Signed-off-by: Philipp Homann <homann.philipp@googlemail.com> * Dump: also dump LFS (fixes #10058) Signed-off-by: Philipp Homann <homann.philipp@googlemail.com> * Dump: never dump CustomPath if CustomPath is a subdir of or equal to AppDataPath (fixes #10365) Signed-off-by: Philipp Homann <homann.philipp@googlemail.com> * Use log.Info instead of fmt.Fprintf Signed-off-by: Philipp Homann <homann.philipp@googlemail.com> * import ordering * make fmt Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: Matti R <matti@mdranta.net>
115 lines
3.4 KiB
Go
115 lines
3.4 KiB
Go
// Copyright 2016 The Snappy-Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// +build !amd64 appengine !gc noasm
|
|
|
|
package snappy
|
|
|
|
// decode writes the decoding of src to dst. It assumes that the varint-encoded
|
|
// length of the decompressed bytes has already been read, and that len(dst)
|
|
// equals that length.
|
|
//
|
|
// It returns 0 on success or a decodeErrCodeXxx error code on failure.
|
|
func decode(dst, src []byte) int {
|
|
var d, s, offset, length int
|
|
for s < len(src) {
|
|
switch src[s] & 0x03 {
|
|
case tagLiteral:
|
|
x := uint32(src[s] >> 2)
|
|
switch {
|
|
case x < 60:
|
|
s++
|
|
case x == 60:
|
|
s += 2
|
|
if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line.
|
|
return decodeErrCodeCorrupt
|
|
}
|
|
x = uint32(src[s-1])
|
|
case x == 61:
|
|
s += 3
|
|
if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line.
|
|
return decodeErrCodeCorrupt
|
|
}
|
|
x = uint32(src[s-2]) | uint32(src[s-1])<<8
|
|
case x == 62:
|
|
s += 4
|
|
if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line.
|
|
return decodeErrCodeCorrupt
|
|
}
|
|
x = uint32(src[s-3]) | uint32(src[s-2])<<8 | uint32(src[s-1])<<16
|
|
case x == 63:
|
|
s += 5
|
|
if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line.
|
|
return decodeErrCodeCorrupt
|
|
}
|
|
x = uint32(src[s-4]) | uint32(src[s-3])<<8 | uint32(src[s-2])<<16 | uint32(src[s-1])<<24
|
|
}
|
|
length = int(x) + 1
|
|
if length <= 0 {
|
|
return decodeErrCodeUnsupportedLiteralLength
|
|
}
|
|
if length > len(dst)-d || length > len(src)-s {
|
|
return decodeErrCodeCorrupt
|
|
}
|
|
copy(dst[d:], src[s:s+length])
|
|
d += length
|
|
s += length
|
|
continue
|
|
|
|
case tagCopy1:
|
|
s += 2
|
|
if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line.
|
|
return decodeErrCodeCorrupt
|
|
}
|
|
length = 4 + int(src[s-2])>>2&0x7
|
|
offset = int(uint32(src[s-2])&0xe0<<3 | uint32(src[s-1]))
|
|
|
|
case tagCopy2:
|
|
s += 3
|
|
if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line.
|
|
return decodeErrCodeCorrupt
|
|
}
|
|
length = 1 + int(src[s-3])>>2
|
|
offset = int(uint32(src[s-2]) | uint32(src[s-1])<<8)
|
|
|
|
case tagCopy4:
|
|
s += 5
|
|
if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line.
|
|
return decodeErrCodeCorrupt
|
|
}
|
|
length = 1 + int(src[s-5])>>2
|
|
offset = int(uint32(src[s-4]) | uint32(src[s-3])<<8 | uint32(src[s-2])<<16 | uint32(src[s-1])<<24)
|
|
}
|
|
|
|
if offset <= 0 || d < offset || length > len(dst)-d {
|
|
return decodeErrCodeCorrupt
|
|
}
|
|
// Copy from an earlier sub-slice of dst to a later sub-slice.
|
|
// If no overlap, use the built-in copy:
|
|
if offset > length {
|
|
copy(dst[d:d+length], dst[d-offset:])
|
|
d += length
|
|
continue
|
|
}
|
|
|
|
// Unlike the built-in copy function, this byte-by-byte copy always runs
|
|
// forwards, even if the slices overlap. Conceptually, this is:
|
|
//
|
|
// d += forwardCopy(dst[d:d+length], dst[d-offset:])
|
|
//
|
|
// We align the slices into a and b and show the compiler they are the same size.
|
|
// This allows the loop to run without bounds checks.
|
|
a := dst[d : d+length]
|
|
b := dst[d-offset:]
|
|
b = b[:len(a)]
|
|
for i := range a {
|
|
a[i] = b[i]
|
|
}
|
|
d += length
|
|
}
|
|
if d != len(dst) {
|
|
return decodeErrCodeCorrupt
|
|
}
|
|
return 0
|
|
}
|