A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/python/cpython/commit/a62ad4730c9b575f140f24074656c0257c86a09a below:

Don't let newline in filename corrupt the out… · python/cpython@a62ad47 · GitHub

File tree Expand file treeCollapse file tree 4 files changed

+21

-0

lines changed

Filter options

Expand file treeCollapse file tree 4 files changed

+21

-0

lines changed Original file line number Diff line number Diff line change

@@ -20,6 +20,10 @@ def uu_encode(input, errors='strict', filename='<data>', mode=0o666):

20 20

read = infile.read

21 21

write = outfile.write

22 22 23 +

# Remove newline chars from filename

24 +

filename = filename.replace('\n','\\n')

25 +

filename = filename.replace('\r','\\r')

26 + 23 27

# Encode

24 28

write(('begin %o %s\n' % (mode & 0o777, filename)).encode('ascii'))

25 29

chunk = read(45)

Original file line number Diff line number Diff line change

@@ -136,6 +136,15 @@ def test_garbage_padding(self):

136 136

decoded = codecs.decode(encodedtext, "uu_codec")

137 137

self.assertEqual(decoded, plaintext)

138 138 139 +

def test_newlines_escaped(self):

140 +

# Test newlines are escaped with uu.encode

141 +

inp = io.BytesIO(plaintext)

142 +

out = io.BytesIO()

143 +

filename = "test.txt\n\roverflow.txt"

144 +

safefilename = b"test.txt\\n\\roverflow.txt"

145 +

uu.encode(inp, out, filename)

146 +

self.assertIn(safefilename, out.getvalue())

147 + 139 148

class UUStdIOTest(unittest.TestCase):

140 149 141 150

def setUp(self):

Original file line number Diff line number Diff line change

@@ -73,6 +73,13 @@ def encode(in_file, out_file, name=None, mode=None, *, backtick=False):

73 73

name = '-'

74 74

if mode is None:

75 75

mode = 0o666

76 + 77 +

#

78 +

# Remove newline chars from name

79 +

#

80 +

name = name.replace('\n','\\n')

81 +

name = name.replace('\r','\\r')

82 + 76 83

#

77 84

# Write the data

78 85

#

Original file line number Diff line number Diff line change

@@ -0,0 +1 @@

1 +

Newline characters have been escaped when performing uu encoding to prevent them from overflowing into to content section of the encoded file. This prevents malicious or accidental modification of data during the decoding process.

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4