From bae858ad9c32978d161a2e37a46403b5a20fec76 Mon Sep 17 00:00:00 2001 From: TC <55949036+tc-hib@users.noreply.github.com> Date: Mon, 18 Mar 2024 17:39:21 +0100 Subject: [PATCH] Version info : accept zero-length string values --- version/binary.go | 5 ++++- .../TestFromBytes_ErrStringLength.golden | Bin 420 -> 420 bytes 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/version/binary.go b/version/binary.go index 5270ed0..4799cf4 100644 --- a/version/binary.go +++ b/version/binary.go @@ -376,7 +376,10 @@ func readString(data []byte, pos *int) (string, error) { func readStringWithLength(data []byte, pos *int, length int) (string, error) { data = data[*pos:] - if length == 0 || length > len(data)/2 { + if length == 0 { + return "", nil + } + if length < 0 || length > len(data)/2 { return "", errors.New(errInvalidStringLength) } diff --git a/version/testdata/TestFromBytes_ErrStringLength.golden b/version/testdata/TestFromBytes_ErrStringLength.golden index 1f853a463746733611140166fd3798b75360496b..ad819cf10e768456838008af136fed754646099f 100644 GIT binary patch delta 11 TcmZ3&yo7neIYz#T=dS_)8aM>; delta 11 TcmZ3&yo7neIYx$w=dS_)8UO_2