Skip to content

Commit

Permalink
Don't panic on unexpected EOF
Browse files Browse the repository at this point in the history
  • Loading branch information
weqqr committed Dec 15, 2023
1 parent 8483073 commit 7b48eee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion internal/tile/downscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tile
import (
"image"
"image/draw"
"log"
"sort"

"github.com/nfnt/resize"
Expand Down Expand Up @@ -77,7 +78,7 @@ func (t *Tiler) downscalePositions(zoom int, positions []render.TilePosition) []

err := raster.SavePNG(target, t.tilePath(pos.X, pos.Y, zoom))
if err != nil {
panic(err)
log.Printf("unable to save image: %v", err)
}

nextPositions = append(nextPositions, render.TilePosition{
Expand Down
14 changes: 7 additions & 7 deletions internal/world/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ func inflate(reader *bytes.Reader) ([]byte, error) {
counter := NewReaderCounter(reader)
z, err := zlib.NewReader(counter)
if err != nil {
panic(err)
return nil, err
}
defer z.Close()

data, err := io.ReadAll(z)
if err != nil {
panic(err)
return nil, err
}

_, err = reader.Seek(position+counter.count, io.SeekStart)
Expand Down Expand Up @@ -142,12 +142,12 @@ func decodeLegacyBlock(reader *bytes.Reader, version uint8) (*MapBlock, error) {

nodeData, err := inflate(reader)
if err != nil {
panic(err)
return nil, err
}

_, err = inflate(reader)
if err != nil {
panic(err)
return nil, err
}

// - uint8 staticObjectVersion
Expand All @@ -158,7 +158,7 @@ func decodeLegacyBlock(reader *bytes.Reader, version uint8) (*MapBlock, error) {

staticObjectCount, err := readU16(reader)
if err != nil {
panic(err)
return nil, err
}

for i := 0; i < int(staticObjectCount); i++ {
Expand All @@ -170,7 +170,7 @@ func decodeLegacyBlock(reader *bytes.Reader, version uint8) (*MapBlock, error) {
}
dataSize, err := readU16(reader)
if err != nil {
panic(err)
return nil, err
}
_, err = reader.Seek(int64(dataSize), io.SeekCurrent)
if err != nil {
Expand Down Expand Up @@ -254,7 +254,7 @@ func DecodeMapBlock(data []byte) (*MapBlock, error) {
if version < 29 {
mapblock, err := decodeLegacyBlock(reader, version)
if err != nil {
panic(err)
return nil, err
}
return mapblock, nil
}
Expand Down

0 comments on commit 7b48eee

Please sign in to comment.