From b5f531b0ba8cb8777abad385d86a0803e85e614d Mon Sep 17 00:00:00 2001 From: "Sascha L. Teichmann" Date: Fri, 8 Apr 2016 23:40:36 +0200 Subject: [PATCH] Before Go 1.7 there is an extra offset needed to decode blocks correctly after the embedded compressed data. In post 1.7 this bug was fixed. We use build tags here to support both cases. --- common/block.go | 7 ++++++- common/post17offset.go | 10 ++++++++++ common/pre17offset.go | 10 ++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 common/post17offset.go create mode 100644 common/pre17offset.go diff --git a/common/block.go b/common/block.go index dec1fe1..9489a07 100644 --- a/common/block.go +++ b/common/block.go @@ -137,7 +137,12 @@ func NewDecodedBlock(data []byte, colors *Colors) (db *DecodedBlock, err error) return } - offset += buf.Pos + 4 + // There is a bug before Go 1.7 that enforces + // to add 4 as an offset after the compressed + // geometry data. This is resolved via build tags + // and definitions in pre17offset.go and + // post17offset.go. + offset += buf.Pos + afterCompressOfs buf.Pos = 0 if offset >= dataLen { return nil, ErrBlockTruncated diff --git a/common/post17offset.go b/common/post17offset.go new file mode 100644 index 0000000..6d9691c --- /dev/null +++ b/common/post17offset.go @@ -0,0 +1,10 @@ +// Copyright 2016 by Sascha L. Teichmann +// Use of this source code is governed by the MIT license +// that can be found in the LICENSE file. + +// +build go1.7 + +package common + +// afterCompressOfs is not necessary after Go 1.7. +const afterCompressOfs = 0 diff --git a/common/pre17offset.go b/common/pre17offset.go new file mode 100644 index 0000000..b7d9a30 --- /dev/null +++ b/common/pre17offset.go @@ -0,0 +1,10 @@ +// Copyright 2016 by Sascha L. Teichmann +// Use of this source code is governed by the MIT license +// that can be found in the LICENSE file. + +// +build !go1.7 + +package common + +// afterCompressOfs is necessary before Go 1.7. +const afterCompressOfs = 4