Closed brlin-tw closed 6 years ago
Here's an unprofessional trace log of GDB in isJar
:
Starting program: /usr/bin/jexec bfg-1.13.0.jar
Breakpoint 1, isJar (
path=path@entry=0x7fffffffc630 "/home/Lin-Buo-Ren/軟體/BFG Repo-Cleaner/bfg-1.13.0.jar")
at /build/openjdk-8-qbZJ70/openjdk-8-8u171-b11/src/jdk/src/solaris/bin/jexec.c:315
315 const char * isJar(const char * path) {
318 int fd = open(path, O_RDONLY);
315 const char * isJar(const char * path) {
316 const char * result = BAD_FILE_MSG;
315 const char * isJar(const char * path) {
318 int fd = open(path, O_RDONLY);
319 if (fd != -1) {
320 unsigned char buf[CHUNK_SIZE];
322 ssize_t count = read(fd, buf, CHUNK_SIZE);
323 if (count >= MIN_SIZE) {
320 unsigned char buf[CHUNK_SIZE];
323 if (count >= MIN_SIZE) {
327 if (GETSIG(buf) == LOCSIG) {
324 result = BAD_MAGIC_MSG;
327 if (GETSIG(buf) == LOCSIG) {
331 off_t start = LOCHDR + flen;
332 off_t end = start + xlen;
331 off_t start = LOCHDR + flen;
332 off_t end = start + xlen;
334 if (end <= count) {
335 end -= 4; // make sure there are 4 bytes to read at start
336 while (start < end) {
352 errno = BAD_MAGIC;
355 close (fd);
359 }
This looks like a non BFG issue. In the same environment:
$ java -version
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-1~deb9u1-b11)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)
$jexec /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/charsets.jar
invalid file (bad magic number): Exec format error
... and same for every other JAR in that OpenJDK deployment. This test is valid even though none of those JARs would have a main class.
See this bug: https://bugs.java.com/bugdatabase/view_bug.do?bug_id=6401361
The submitter of the incident report informs me that the jar file was created using Maven 2 which most likely doesn't set the required "0xcafe" tag in the jar file. (We've been really bad about informing the world about this, partly because we do it rather sloppily - not in agreement with zip best practices. Ah, history.)
That magic number seems to be really badly applied. I'm having trouble finding any JAR which doesn't start with P K 003 004
. Even fresh JARs created with jar
. For which JARs is this working for you?
Sounds like an OpenJDK bug.
I take some of the above back - seems like the magic might only apply to "executable" JARs ... still seems like an OpenJDK issue with the utility being too strict though? Since the Maven archiver doesn't seem to produce that magic for executable jars.
jexec
in OpenJDK 10.0.1 happily runs the BFG jar, so I'm going to say that OpenJDK relaxed the magic number checking in the tool, but not back-ported to jdk8. So OpenJDK issue.
I file it to OpenJDK then, thanks for helping.
In Debian systems that installs OpenJDK, they seem to be setting up
jexec
as the binfmt interpreter of launching JAR files (/usr/share/binfmts/jar
). However when attempting to run BFG's jar file usingjexec
it fails with "invalid file (bad magic number): Exec format error" error message.Refer
jexec
's source here: http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/tip/src/solaris/bin/jexec.c , this might indicate that some signatures are not matched but I'm not sure.jexec bfg-1.13.0.jar.ltrace.log jexec bfg-1.13.0.jar.strace.log
This issue prevents users from directly execute BFG that are installed in PATHs.
Additional Information
I'm using a third-party OpenJDK installation from ppa:no1wantdthisname/openjdk-fontfix