Fix EOF detection with CI artifacts metadata

There are some corner cases where a perfectly correct GZIP stream may
not hit the EOF until another read is attempted. We now skip the entry
if we don't see any valid data, which allows the EOF check to work
properly.

Closes https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/22479
This commit is contained in:
Stan Hu 2018-10-18 17:01:55 -07:00
parent 5edf87d0ac
commit 4c4d1b7928
2 changed files with 10 additions and 2 deletions

View File

@ -0,0 +1,5 @@
---
title: Fix EOF detection with CI artifacts metadata
merge_request: 22479
author:
type: fixed

View File

@ -59,9 +59,12 @@ module Gitlab
until gz.eof?
begin
path = read_string(gz).force_encoding('UTF-8')
meta = read_string(gz).force_encoding('UTF-8')
path = read_string(gz)&.force_encoding('UTF-8')
meta = read_string(gz)&.force_encoding('UTF-8')
# We might hit an EOF while reading either value, so we should
# abort if we don't get any data.
next unless path && meta
next unless path.valid_encoding? && meta.valid_encoding?
next unless path =~ match_pattern
next if path =~ INVALID_PATH_PATTERN