[go: up one dir, main page]

Skip to content

Commit

Permalink
added checking for ZIP end-of-central directory header for Linux i386…
Browse files Browse the repository at this point in the history
… code running Docker on macOS Ventura 13 with Apple Silicon
  • Loading branch information
Peter Szabo committed Feb 21, 2023
1 parent ef6bd64 commit 81b36c4
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions calculate_path.2.7.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

/* StaticPython */ /* StaticPython-appended */
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
static void calculate_path (void) {
extern char *Py_GetProgramName(void);

Expand Down Expand Up @@ -52,14 +54,29 @@ static void calculate_path (void) {

/**** pts ****/
{ int fd = open(proc_exe_path, O_RDONLY);
char hdr[22];
/* fprintf(stderr, "progpath=(%s)\n", progpath); */
if (fd < 0) { /* If /proc is not avaialbe, e.g. in chroot */
after_bad_proc_exe:
xzip_path = progpath; /* Use argv[0] for the .zip filename */
} else {
xzip_path = proc_exe_path;
if (lseek(fd, -22, SEEK_END) < 0) {
bad_proc_exe:
close(fd);
goto after_bad_proc_exe;
}
if (read(fd, hdr, 22) != 22) goto bad_proc_exe;
/* ZIP end-ef-central-directory header with comment size == 0. */
/* We check this because Linux i386 code running Docker on macOS
* Ventura 13 with Apple Silicon doesn't have a working
* /proc/self/exe, so we fall back to progpath (arg[0], sys.interpreter).
*/
if (memcmp(hdr, "PK\5\6", 4) != 0 || hdr[20] != 0 || hdr[21] != 0) goto bad_proc_exe;
close(fd);
}
}
/*fprintf(stderr, "info: xzip_path=(%s)\n", xzip_path);*/

/**** pts ****/
if (rtpypath == NULL || rtpypath[0] == '\0') {
Expand Down

0 comments on commit 81b36c4

Please sign in to comment.