From 799216896017add174ae14b97756936ceb26b966 Mon Sep 17 00:00:00 2001
From: Paul Moore
Date: Tue, 12 Jul 2022 15:14:17 +0100
Subject: [PATCH 1/3] Fix off-by-one error in Windows launcher
---
PC/launcher2.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/PC/launcher2.c b/PC/launcher2.c
index ae11f4f024a904..66462f05618ff9 100644
--- a/PC/launcher2.c
+++ b/PC/launcher2.c
@@ -874,7 +874,7 @@ checkShebang(SearchInfo *search)
while (--bytesRead > 0 && *++b != '\r' && *b != '\n') { }
wchar_t *shebang;
int shebangLength;
- int exitCode = _decodeShebang(search, start, (int)(b - start + 1), onlyUtf8, &shebang, &shebangLength);
+ int exitCode = _decodeShebang(search, start, (int)(b - start), onlyUtf8, &shebang, &shebangLength);
if (exitCode) {
return exitCode;
}
From 2262bef2d61db9f6f6325305a1d88d564451d7bb Mon Sep 17 00:00:00 2001
From: Paul Moore
Date: Tue, 12 Jul 2022 19:56:23 +0100
Subject: [PATCH 2/3] Fix the case where there's no newline at the end of the
shebang line, and add extra tests
---
Lib/test/test_launcher.py | 24 ++++++++++++++++++++++++
PC/launcher2.c | 4 +++-
2 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/Lib/test/test_launcher.py b/Lib/test/test_launcher.py
index cd7b944f98f586..50a2e8c03d6473 100644
--- a/Lib/test/test_launcher.py
+++ b/Lib/test/test_launcher.py
@@ -515,6 +515,30 @@ def test_py3_shebang(self):
self.assertEqual("3.100-arm64", data["SearchInfo.tag"])
self.assertEqual(f"X.Y-arm64.exe -X fake_arg_for_test -prearg {script} -postarg", data["stdout"].strip())
+ def test_py_shebang_nl(self):
+ with self.py_ini(TEST_PY_COMMANDS):
+ with self.script("#! /usr/bin/env python -prearg\n") as script:
+ data = self.run_py([script, "-postarg"])
+ self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
+ self.assertEqual("3.100", data["SearchInfo.tag"])
+ self.assertEqual(f"X.Y.exe -prearg {script} -postarg", data["stdout"].strip())
+
+ def test_py2_shebang_nl(self):
+ with self.py_ini(TEST_PY_COMMANDS):
+ with self.script("#! /usr/bin/env python2 -prearg\n") as script:
+ data = self.run_py([script, "-postarg"])
+ self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
+ self.assertEqual("3.100-32", data["SearchInfo.tag"])
+ self.assertEqual(f"X.Y-32.exe -prearg {script} -postarg", data["stdout"].strip())
+
+ def test_py3_shebang_nl(self):
+ with self.py_ini(TEST_PY_COMMANDS):
+ with self.script("#! /usr/bin/env python3 -prearg\n") as script:
+ data = self.run_py([script, "-postarg"])
+ self.assertEqual("PythonTestSuite", data["SearchInfo.company"])
+ self.assertEqual("3.100-arm64", data["SearchInfo.tag"])
+ self.assertEqual(f"X.Y-arm64.exe -X fake_arg_for_test -prearg {script} -postarg", data["stdout"].strip())
+
def test_install(self):
data = self.run_py(["-V:3.10"], env={"PYLAUNCHER_ALWAYS_INSTALL": "1"}, expect_returncode=111)
cmd = data["stdout"].strip()
diff --git a/PC/launcher2.c b/PC/launcher2.c
index 66462f05618ff9..c8ed1b0f7c8a6d 100644
--- a/PC/launcher2.c
+++ b/PC/launcher2.c
@@ -874,7 +874,9 @@ checkShebang(SearchInfo *search)
while (--bytesRead > 0 && *++b != '\r' && *b != '\n') { }
wchar_t *shebang;
int shebangLength;
- int exitCode = _decodeShebang(search, start, (int)(b - start), onlyUtf8, &shebang, &shebangLength);
+ // We add 1 when bytesRead==0, as in that case we hit EOF and b points
+ // to the last character in the file, not the newline
+ int exitCode = _decodeShebang(search, start, (int)(b - start + (bytesRead == 0)), onlyUtf8, &shebang, &shebangLength);
if (exitCode) {
return exitCode;
}
From 5226ff39876e83a5290cdda80cdc73d88a6a68db Mon Sep 17 00:00:00 2001
From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com>
Date: Tue, 12 Jul 2022 20:45:46 +0000
Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?=
=?UTF-8?q?rb=5Fit.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../next/Windows/2022-07-12-20-45-43.gh-issue-94772.uNMmdG.rst | 1 +
1 file changed, 1 insertion(+)
create mode 100644 Misc/NEWS.d/next/Windows/2022-07-12-20-45-43.gh-issue-94772.uNMmdG.rst
diff --git a/Misc/NEWS.d/next/Windows/2022-07-12-20-45-43.gh-issue-94772.uNMmdG.rst b/Misc/NEWS.d/next/Windows/2022-07-12-20-45-43.gh-issue-94772.uNMmdG.rst
new file mode 100644
index 00000000000000..bb5ab754484eb3
--- /dev/null
+++ b/Misc/NEWS.d/next/Windows/2022-07-12-20-45-43.gh-issue-94772.uNMmdG.rst
@@ -0,0 +1 @@
+Fix incorrect handling of shebang lines in py.exe launcher