Browse Source

Fix segfault with non existant file

Dashie der otter 9 months ago
parent
commit
e3f00561ac
Signed by: Dashie <dashie@sigpipe.me> GPG Key ID: C2D57B325840B755
5 changed files with 23 additions and 12 deletions
  1. 1
    1
      TODO.org
  2. 1
    0
      conf/locale/locale_en-US.ini
  3. 1
    0
      conf/locale/locale_fr-FR.ini
  4. 6
    0
      routers/gitxt/gitxt.go
  5. 14
    11
      stuff/gite/gite.go

+ 1
- 1
TODO.org View File

@@ -8,7 +8,7 @@
8 8
 * Ways of improvement
9 9
 ** TODO Merge AssignUser and AssignRepository ?
10 10
 ** TODO Cleanup gogs imports of unused bits
11
-** TODO Non existant file in git for raw file: git_object_lookup_prefix: Assertion `repo && object_out && id' failed.
11
+** DONE Non existant file in git for raw file: git_object_lookup_prefix: Assertion `repo && object_out && id' failed.
12 12
 ** DONE Can't add files with filename "/some/thing/foo.bar"
13 13
 ** DONE Investigate the non-working context.Flash when not using a redirect
14 14
 ** DONE Correctly handle filenames with a /, like raw view

+ 1
- 0
conf/locale/locale_en-US.ini View File

@@ -101,6 +101,7 @@ over_page_size = "Page size limit exceeded and file won't me displayed."
101 101
 load_image = "Load image"
102 102
 load_pdf = "Load PDF Viewer"
103 103
 is_binary = "Can't display binary files."
104
+file_not_found = "File not found"
104 105
 
105 106
 [gitxt_list]
106 107
 title = "List of git.txts"

+ 1
- 0
conf/locale/locale_fr-FR.ini View File

@@ -101,6 +101,7 @@ over_page_size = "Limite de taille pour la page atteinte et le fichier ne sera p
101 101
 load_image = "Charger image"
102 102
 load_pdf = "Charger le lecteur de PDF"
103 103
 is_binary = "Impossible d'afficher les fichiers binaires."
104
+file_not_found = "Fichier non trouvé"
104 105
 
105 106
 [gitxt_list]
106 107
 title = "Liste des git.txts"

+ 6
- 0
routers/gitxt/gitxt.go View File

@@ -351,6 +351,12 @@ func RawFile(ctx *context.Context) {
351 351
 		return
352 352
 	}
353 353
 
354
+	// File not found
355
+	if treeFile.ID == "" {
356
+		ctx.Error(404)
357
+		return
358
+	}
359
+
354 360
 	if treeFile.Size > setting.Bloby.MaxRawSize {
355 361
 		ctx.Handle(500, "MaxRawSize", nil)
356 362
 		return

+ 14
- 11
stuff/gite/gite.go View File

@@ -1,15 +1,15 @@
1 1
 package gite
2 2
 
3 3
 import (
4
-	"gopkg.in/libgit2/git2go.v25"
5
-	"strings"
6
-	"path/filepath"
7
-	"archive/zip"
8 4
 	"archive/tar"
9
-	"os"
5
+	"archive/zip"
10 6
 	"dev.sigpipe.me/dashie/git.txt/setting"
11 7
 	"github.com/rakyll/magicmime"
8
+	"gopkg.in/libgit2/git2go.v25"
12 9
 	gotemplate "html/template"
10
+	"os"
11
+	"path/filepath"
12
+	"strings"
13 13
 )
14 14
 
15 15
 type errorString struct {
@@ -23,7 +23,6 @@ func (e *errorString) Error() string {
23 23
 // Some stuff to play with git because easy things are not always easy
24 24
 // Some of theses functions comes from https://git.nurupoga.org/kr/_discorde/src/master/discorde/tree.go
25 25
 
26
-
27 26
 // A TreeEntry represents a file of a git repository.
28 27
 type TreeEntry struct {
29 28
 	Path     string
@@ -197,7 +196,6 @@ func WriteZipArchiveFromRepository(repo *git.Repository, archivePath string) (er
197 196
 	return
198 197
 }
199 198
 
200
-
201 199
 // TreeFiles struct to get root tree without depth and contents
202 200
 type TreeFiles struct {
203 201
 	ID           string
@@ -205,7 +203,7 @@ type TreeFiles struct {
205 203
 	Content      string
206 204
 	ContentB     []byte
207 205
 	ContentH     gotemplate.HTML
208
-	Size         int64	// bytes
206
+	Size         int64 // bytes
209 207
 	OverSize     bool
210 208
 	IsBinary     bool
211 209
 	OverPageSize bool
@@ -267,7 +265,7 @@ func getTreeFile(repo *git.Repository, path string, curSize int64) (treeFile Tre
267 265
 			treeFile.OverSize = true
268 266
 		} else {
269 267
 			// If we still are in the limits, check the page display size
270
-			if curSize + blob.Size() > setting.Bloby.MaxPageDisplay {
268
+			if curSize+blob.Size() > setting.Bloby.MaxPageDisplay {
271 269
 				treeFile.OverPageSize = true
272 270
 				treeFile.Content = ""
273 271
 			} else {
@@ -295,9 +293,14 @@ func GetTreeFileNoLimit(repo *git.Repository, path string) (treeFile TreeFiles,
295 293
 	}
296 294
 	defer magicmime.Close()
297 295
 
298
-
299 296
 	var entry git.TreeEntry
300 297
 	tree.Walk(getTreeEntryByPath(&entry, path))
298
+
299
+	// If we don't get an entry, the file does not exist!
300
+	if entry.Id == nil {
301
+		return
302
+	}
303
+
301 304
 	blob, err := repo.LookupBlob(entry.Id)
302 305
 	if err != nil {
303 306
 		return
@@ -372,4 +375,4 @@ func GetTreeFileOid(repo *git.Repository, path string) (oid *git.Oid, err error)
372 375
 	tree.Walk(getTreeEntryByPath(&entry, path))
373 376
 
374 377
 	return entry.Id, err
375
-}
378
+}

Loading…
Cancel
Save