stephen304 / bitcannon

A torrent index archiving, browsing, and backup tool
http://bitcannon.io/
MIT License
408 stars 40 forks source link

"runtime error: index out of range" when scraping an invalid torrent #77

Open aidanharris opened 9 years ago

aidanharris commented 9 years ago

This bug is reproducible as follows:

curl http://127.0.0.1:1337/scrape/invalidTorrent

EDIT: The fix for this is probably to do whatever happens when making an invalid request to /torrent/invalidTorrent and output the following:

{"message":"Torrent not found."}

SECOND EDIT: I'm new to programming in Golang so I'm not sure how efficient this is but I managed to solve this issue by adding the following to the beggining of of the apiScrape function:

defer func() {
        if s := recover(); s != nil {
            r.JSON(404, map[string]interface{}{"message": "Torrent not found."})
            return
        }
    }()
stephen304 commented 9 years ago

Sorry for the late response and thank you for investigating this!

I'll leave this open until I get a chance to implement. I got a couple weeks left of school before the summer.