Merge ~smoser/cloud-init:fix/1768600-utf8-in-user-data into cloud-init:master

Proposed by Scott Moser
Status: Rejected
Rejected by: Scott Moser
Proposed branch: ~smoser/cloud-init:fix/1768600-utf8-in-user-data
Merge into: cloud-init:master
Diff against target: 42 lines (+13/-9)
1 file modified
cloudinit/ (+13/-9)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
cloud-init Commiters Pending
Review via email:

Commit message

Be more safe on string/bytes when writing multipart user-data to disk.

When creating the multipart mime message that is written as
user-data.txt.i, cloud-init losing data on conversion to some things
as a string.

LP: #1768600

Description of the change

see commit message

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:b6d09aa29b1c6170b4014116a44accf9b8281666
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    SUCCESS: MAAS Compatability Testing
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:

review: Approve (continuous-integration)
Revision history for this message
Scott Moser (smoser) wrote :

There was an error fetching revisions from git servers. Please try again in a few minutes. If the problem persists, contact Launchpad support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/ b/cloudinit/
2index 8f6aba1..ed83d2d 100644
3--- a/cloudinit/
4+++ b/cloudinit/
5@@ -337,8 +337,10 @@ def is_skippable(part):
7 # Coverts a raw string into a mime message
8 def convert_string(raw_data, content_type=NOT_MULTIPART_TYPE):
9+ """convert a string (more likely bytes) or a message into
10+ a mime message."""
11 if not raw_data:
12- raw_data = ''
13+ raw_data = b''
15 def create_binmsg(data, content_type):
16 maintype, subtype = content_type.split("/", 1)
17@@ -346,15 +348,17 @@ def convert_string(raw_data, content_type=NOT_MULTIPART_TYPE):
18 msg.set_payload(data)
19 return msg
21- try:
22- data = util.decode_binary(util.decomp_gzip(raw_data))
23- if "mime-version:" in data[0:4096].lower():
24- msg = util.message_from_string(data)
25- else:
26- msg = create_binmsg(data, content_type)
27- except UnicodeDecodeError:
28- msg = create_binmsg(raw_data, content_type)
29+ if isinstance(raw_data, six.text_type):
30+ bdata = raw_data.encode('utf-8')
31+ else:
32+ bdata = raw_data
33+ bdata = util.decomp_gzip(bdata, decode=False)
34+ if b"mime-version:" in bdata[0:4096].lower():
35+ msg = util.message_from_string(bdata.decode('utf-8'))
36+ else:
37+ msg = create_binmsg(bdata, content_type)
39 return msg
42 # vi: ts=4 expandtab


People subscribed via source and target branches