View Issue Details

IDProjectCategoryView StatusLast Update
0000059fileGeneralpublic2019-10-29 01:18
Reportermagicus Assigned Tochristos  
PrioritynormalSeverityminorReproducibilityalways
Status assignedResolutionopen 
Product Version5.35 
Summary0000059: Magic is missing for Java jmod and module image files
DescriptionThere is no magic formula for Java jmod and image files (as produced by jlink); these are artefacts generated by Java since JDK 9.
Steps To ReproduceActual results:

$ file jdk/jmods/java.base.jmod
jdk/jmods/java.base.jmod: Zip archive data

$ file jdk/lib/modules
jdk/lib/modules: data

Expected results:

$ file jdk/jmods/java.base.jmod
jdk/jmods/java.base.jmod: Java jmod module, version 1.0

$ file jdk/lib/modules
jdk/lib/modules: Java module image (little endian), version 1.0
Additional InformationProvided patch has been tested on all three types (jmod, BE image and LE image), and a sanity check that it did not break zip detection.
TagsNo tags attached.

Activities

magicus

2019-01-30 11:43

reporter  

add-java-jmod-and-image.patch (1,190 bytes)   
commit 3c76cc7d6dd0b0d5e4c099d54396d01e1348cd11
Author: Magnus Ihse Bursie <mag@icus.se>
Date:   Wed Jan 30 12:36:04 2019 +0100

    Add magic definitions for Java jmod and Java image.

diff --git a/magic/Magdir/java b/magic/Magdir/java
index 18e82eaf..21a3cfb5 100644
--- a/magic/Magdir/java
+++ b/magic/Magdir/java
@@ -25,3 +25,24 @@
 >0x12	byte		0
 >>0x11	ubyte-0x31	<2      Java HPROF dump,
 >>>0x17	beqdate/1000	x       created %s
+
+# Java jmod module
+# See https://hg.openjdk.java.net/jdk9/jdk9/jdk/file/tip/src/java.base/share/classes/jdk/internal/jmod/JmodFile.java
+0	beshort		0x4a4d		Java jmod module
+# jmod header is followed by zip entry; make sure we win over zip
+!:strength + 20
+>2	byte	>0x00	\b, version %d
+>3	byte	x	\b.%d
+!:mime	application/x-java-jmod
+
+# Java jlinked image
+# See https://hg.openjdk.java.net/jdk9/jdk9/jdk/file/tip/src/java.base/share/native/libjimage/imageFile.hpp
+0	belong	0xcafedada	Java module image (big endian)
+>4	beshort	>0x00	\b, version %d
+>6	beshort	x	\b.%d
+!:mime	application/x-java-image
+
+0	lelong	0xcafedada	Java module image (little endian)
+>6	leshort	>0x00	\b, version %d
+>4	leshort	x	\b.%d
+!:mime	application/x-java-image
add-java-jmod-and-image.patch (1,190 bytes)   

christos

2019-02-18 16:53

manager   ~0003209

Thanks! JM magic is too short. I only added it for v1.0 so that it does not generate false positives.

magicus

2019-10-23 11:35

reporter   ~0003319

I just noticed right now that my patch got stuck here, sorry for the long delay in my response.

I'm not sure what you mean. By "JM magic", do you mean the jmod beshort 0x4a4d marker?

I agree that a 32 bit marker had been preferable, but that's not the way the file format is designed. :-( The jmod header is followed by a zip entry. Is there a way to link this requirement to the zip definition? If so, the identification mechanism surely cannot be too generic. (I assume you worry about false positives.) I do not understand the syntax of the magic file good enough to figure out how to do that, if it's possible.

I can see only four possible solutions:
1) specify that a zip header must follow (if this possible)
2) copy/reimplement the definition of the zip header with a slight offset into the jmod definition
3) accept the entry anyway, since we have nothing else to go on
4) omit that part of the patch and never be able to support jmod files

magicus

2019-10-23 11:43

reporter   ~0003320

Ah, now I understand. 0x4a4d of course spells "JM". And what you are saying is that if I hard-code the match to jmod version 1.0, I'd get 0x4a4d0100, and that would be an acceptable magic marker?

christos

2019-10-29 01:18

manager   ~0003321

Yes, that would even be better (to make it look further for a zip header... I've already added the 0100, but we can make it better if we just match on the JM then the zip header and print the version dynamically...

Issue History

Date Modified Username Field Change
2019-01-30 11:43 magicus New Issue
2019-01-30 11:43 magicus File Added: add-java-jmod-and-image.patch
2019-02-18 16:53 christos Assigned To => christos
2019-02-18 16:53 christos Status new => assigned
2019-02-18 16:53 christos Status assigned => feedback
2019-02-18 16:53 christos Note Added: 0003209
2019-10-23 11:35 magicus Note Added: 0003319
2019-10-23 11:35 magicus Status feedback => assigned
2019-10-23 11:43 magicus Note Added: 0003320
2019-10-29 01:18 christos Note Added: 0003321