Fix image resizing bug.

If the image was already smaller than the treshold, it was
trying to re-use a buffer that was already consumed.

Change-Id: Ifb61fe0bae401462188a8e08ddf2937c7080c4df
This commit is contained in:
Brad Fitzpatrick 2011-07-08 13:33:55 -07:00
parent 494b95536f
commit 711bcfbd44
2 changed files with 6 additions and 1 deletions

View File

@ -68,7 +68,11 @@ func (ih *ImageHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request, fil
var buf bytes.Buffer
n, err := io.Copy(&buf, fr)
i, format, err := image.Decode(&buf)
if err != nil {
log.Printf("image resize: error reading image %s: %v", file, err)
return
}
i, format, err := image.Decode(bytes.NewBuffer(buf.Bytes()))
if err != nil {
http.Error(rw, "Can't serve file: "+err.String(), 500)
return

View File

@ -464,6 +464,7 @@ func (pr *publishRequest) serveSubresFileDownload() {
func (pr *publishRequest) serveScaledImage(des *search.DescribedBlob, maxWidth, maxHeight int) {
fileref, _, ok := pr.fileSchemaRefFromBlob(des)
if !ok {
log.Printf("scaled image fail; failed to get file schema from des %q", des.BlobRef)
return
}
th := &ImageHandler{