aboutsummaryrefslogtreecommitdiffstats
path: root/modules/references
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-06-26 00:11:33 +0100
committerGitHub <noreply@github.com>2021-06-26 01:11:33 +0200
commit62a4879e84c7474dd72ab0eb4c54923f2690510c (patch)
tree0302b319060aedf229e3fc1a834361be6fe6220c /modules/references
parent9b33d18899b7e825e4754969ffcc9d7b541d2d28 (diff)
downloadgitea-62a4879e84c7474dd72ab0eb4c54923f2690510c.tar.gz
gitea-62a4879e84c7474dd72ab0eb4c54923f2690510c.zip
Improve efficiency in FindRenderizableReferenceNumeric and getReferences (#16251)
* Fuzzer finds an NPE due to incorrect URLPrefix The Fuzzer is running on a non-repo urlprefix which is incorrect for RenderRaw * Make FindRenderizableReferenceNumeric and getReferences more efficient Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'modules/references')
-rw-r--r--modules/references/references.go16
1 files changed, 9 insertions, 7 deletions
diff --git a/modules/references/references.go b/modules/references/references.go
index 106e66b47b..ef859abcc7 100644
--- a/modules/references/references.go
+++ b/modules/references/references.go
@@ -5,6 +5,7 @@
package references
import (
+ "bytes"
"net/url"
"regexp"
"strconv"
@@ -14,6 +15,8 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup/mdstripper"
"code.gitea.io/gitea/modules/setting"
+
+ "github.com/yuin/goldmark/util"
)
var (
@@ -321,7 +324,7 @@ func FindRenderizableReferenceNumeric(content string, prOnly bool) (bool, *Rende
return false, nil
}
}
- r := getCrossReference([]byte(content), match[2], match[3], false, prOnly)
+ r := getCrossReference(util.StringToReadOnlyBytes(content), match[2], match[3], false, prOnly)
if r == nil {
return false, nil
}
@@ -465,18 +468,17 @@ func findAllIssueReferencesBytes(content []byte, links []string) []*rawReference
}
func getCrossReference(content []byte, start, end int, fromLink bool, prOnly bool) *rawReference {
- refid := string(content[start:end])
- sep := strings.IndexAny(refid, "#!")
+ sep := bytes.IndexAny(content[start:end], "#!")
if sep < 0 {
return nil
}
- isPull := refid[sep] == '!'
+ isPull := content[start+sep] == '!'
if prOnly && !isPull {
return nil
}
- repo := refid[:sep]
- issue := refid[sep+1:]
- index, err := strconv.ParseInt(issue, 10, 64)
+ repo := string(content[start : start+sep])
+ issue := string(content[start+sep+1 : end])
+ index, err := strconv.ParseInt(string(issue), 10, 64)
if err != nil {
return nil
}