Skip to content

Commit c0450c0

Browse files
authored
query: do not handle non-decodable non-gzipped content (canonical#543)
1 parent db86753 commit c0450c0

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

cloudinit/cmd/query.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,11 @@ def load_userdata(ud_file_path):
8686
8787
@returns: String of uncompressed userdata if possible, otherwise bytes.
8888
"""
89+
bdata = util.load_file(ud_file_path, decode=False)
8990
try:
90-
return util.load_file(ud_file_path)
91+
return bdata.decode('utf-8')
9192
except UnicodeDecodeError:
92-
encoded_data = util.load_file(ud_file_path, decode=False)
93-
try:
94-
return util.decomp_gzip(encoded_data, quiet=False)
95-
except util.DecompressionError:
96-
return encoded_data
93+
return util.decomp_gzip(bdata, quiet=False, decode=True)
9794

9895

9996
def handle_args(name, args):

cloudinit/cmd/tests/test_query.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,6 @@ def test_handle_args_root_fallsback_to_instance_data(self, caplog, tmpdir):
144144
('ud'.encode('utf-8'), 'ud', 'vd'.encode('utf-8'), 'vd'),
145145
(_gzip_data(b'ud'), 'ud', _gzip_data(b'vd'), 'vd'),
146146
(_gzip_data('ud'.encode('utf-8')), 'ud', _gzip_data(b'vd'), 'vd'),
147-
(_gzip_data(b'ud') + b'invalid', 'ci-b64:',
148-
_gzip_data(b'vd') + b'invalid', 'ci-b64:'),
149-
# non-utf-8 encodable content
150-
('hi mom'.encode('utf-16'), 'ci-b64://5oAGkAIABtAG8AbQA=',
151-
'hi pops'.encode('utf-16'), 'ci-b64://5oAGkAIABwAG8AcABzAA=='),
152147
)
153148
)
154149
def test_handle_args_root_processes_user_data(

0 commit comments

Comments
 (0)