From e733897f5e4eacd8b3a0792b626fd96cdaa70954 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Tue, 20 Oct 2020 14:52:34 +0200 Subject: [PATCH] parse checksum even when no EOL is found (#285) In case a checksum file does not end with '\n', the checksum can still be valid. When hitting EOF, verify that the read line is non-empty, and continue with parsing. --- checksum.go | 5 ++++- get_test.go | 7 ++++++- testdata/checksum-file/sha512-p-EOF.sum | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 testdata/checksum-file/sha512-p-EOF.sum diff --git a/checksum.go b/checksum.go index 986b23137..958bbede5 100644 --- a/checksum.go +++ b/checksum.go @@ -272,7 +272,10 @@ func (c *Client) checksumFromFile(ctx context.Context, checksumURL string, check return nil, fmt.Errorf( "Error reading checksum file: %s", err) } - break + if line == "" { + break + } + // parse the line, if we hit EOF, but the line is not empty } checksum, err := parseChecksumLine(line) if err != nil || checksum == nil { diff --git a/get_test.go b/get_test.go index 0ee215aaa..c240f7051 100644 --- a/get_test.go +++ b/get_test.go @@ -570,13 +570,18 @@ func TestGetFile_checksum_from_file(t *testing.T) { true, false, }, - // sha512 { "?checksum=file:" + checksums + "/CHECKSUM_sha256_gpg", true, false, }, + { + // checksum file does not have EOL, ends line with EOF + "?checksum=file:" + httpChecksums.URL + "/sha512-p-EOF.sum", + true, + false, + }, } for _, tc := range cases { diff --git a/testdata/checksum-file/sha512-p-EOF.sum b/testdata/checksum-file/sha512-p-EOF.sum new file mode 100644 index 000000000..2c72e8817 --- /dev/null +++ b/testdata/checksum-file/sha512-p-EOF.sum @@ -0,0 +1 @@ +060a8cc41c501e41b4537029661090597aeb4366702ac3cae8959f24b2c49005d6bd339833ebbeb481b127ac822d70b937c1637c8d0eaf81b6979d4c1d75d0e1 \ No newline at end of file