From 82209cf9556d070fc617f54bb2277b812090b88e Mon Sep 17 00:00:00 2001 From: Vaidas Pilkauskas Date: Mon, 4 Jan 2021 16:33:42 +0200 Subject: [PATCH 1/5] ijar: fix manifest sections handling --- third_party/ijar/ijar.cc | 20 ++++++++++++++------ third_party/ijar/test/BUILD | 10 ++++++++++ third_party/ijar/test/IjarTests.java | 21 +++++++++++++++++++++ 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/third_party/ijar/ijar.cc b/third_party/ijar/ijar.cc index 1e51291d3e13d3..1d9fe01aa2b958 100644 --- a/third_party/ijar/ijar.cc +++ b/third_party/ijar/ijar.cc @@ -298,7 +298,9 @@ u1 *JarCopierProcessor::AppendTargetLabelToManifest( const char *target_label, const char *injecting_rule_kind) { const char *line_start = (const char *)manifest_data; const char *data_end = (const char *)manifest_data + size; - while (line_start < data_end) { + + // Write main attributes part + while (line_start < data_end && line_start[0] != '\r' && line_start[0] != '\n') { const char *line_end = strchr(line_start, '\n'); // Go past return char to point to next line, or to end of data buffer line_end = line_end != nullptr ? line_end + 1 : data_end; @@ -309,18 +311,24 @@ u1 *JarCopierProcessor::AppendTargetLabelToManifest( strncmp(line_start, INJECTING_RULE_KIND_KEY, INJECTING_RULE_KIND_KEY_LENGTH) != 0) { size_t len = line_end - line_start; - // Skip empty lines - if (len > 0 && line_start[0] != '\r' && line_start[0] != '\n') { - memcpy(buf, line_start, len); - buf += len; - } + memcpy(buf, line_start, len); + buf += len; } line_start = line_end; } + + // Append target label and, if given, rule kind buf = WriteManifestAttr(buf, TARGET_LABEL_KEY, target_label); if (injecting_rule_kind != nullptr) { buf = WriteManifestAttr(buf, INJECTING_RULE_KIND_KEY, injecting_rule_kind); } + + // Write the rest of the manifest file + size_t sections_len = data_end - line_start; + if (sections_len > 0) { + memcpy(buf, line_start, sections_len); + buf += sections_len; + } return buf; } diff --git a/third_party/ijar/test/BUILD b/third_party/ijar/test/BUILD index daf0f16a78bbcf..3061fecc001e91 100644 --- a/third_party/ijar/test/BUILD +++ b/third_party/ijar/test/BUILD @@ -144,6 +144,14 @@ genrule( tools = ["//third_party/ijar"], ) +genrule( + name = "jar_with_manifest_sections", + srcs = ["jar-with-manifest-sections.jar"], + outs = ["jar-with-manifest-sections-nostrip.jar"], + cmd = "$(location //third_party/ijar) --target_label //foo:foo --nostrip_jar $< $@", + tools = ["//third_party/ijar"], +) + genrule( name = "jar_without_manifest_nostrip_idempotence", srcs = ["jar-without-manifest-nostrip.jar"], @@ -305,6 +313,7 @@ java_test( "UseRestrictedAnnotation.java", "jar-with-manifest.jar", "jar-with-manifest-and-target-label.jar", + "jar-with-manifest-sections.jar", "jar-without-manifest.jar", "package-info.java", ":empty_with_target_label", @@ -314,6 +323,7 @@ java_test( ":interface_ijar_testlib_with_target_label", ":jar_with_manifest_and_target_label_nostrip", ":jar_with_manifest_nostrip", + ":jar_with_manifest_sections", ":jar_without_manifest_nostrip", ":jar_without_manifest_nostrip_idempotence", ":kotlin_module-interface.jar", diff --git a/third_party/ijar/test/IjarTests.java b/third_party/ijar/test/IjarTests.java index 7563f599ca39c0..ecad9c3c712f57 100644 --- a/third_party/ijar/test/IjarTests.java +++ b/third_party/ijar/test/IjarTests.java @@ -399,6 +399,27 @@ public void testNoStripJarWithoutManifest() throws Exception { } } + @Test + public void testPreserveManifestSections() throws Exception { + try (JarFile stripped = new JarFile( + "third_party/ijar/test/jar-with-manifest-sections-nostrip.jar")) { + ImmutableList strippedEntries = + stripped.stream().map(JarEntry::getName).collect(toImmutableList()); + + assertThat(strippedEntries.get(0)).isEqualTo("META-INF/"); + assertThat(strippedEntries.get(1)).isEqualTo("META-INF/MANIFEST.MF"); + Manifest manifest = stripped.getManifest(); + Attributes attributes = manifest.getMainAttributes(); + assertThat(attributes.getValue("Target-Label")).isEqualTo("//foo:foo"); + + Attributes sectionAttributes1 = manifest.getAttributes("foo"); + assertThat(sectionAttributes1.getValue("Foo")).isEqualTo("bar"); + + Attributes sectionAttributes2 = manifest.getAttributes("baz"); + assertThat(sectionAttributes2.getValue("Another")).isEqualTo("bar"); + } + } + // Tests idempotence of --nostrip @Test public void testNoStripIdempotence() throws Exception { From b5f0f25a7ca352788d08ebde54ad6aac2e18370e Mon Sep 17 00:00:00 2001 From: Vaidas Pilkauskas Date: Mon, 4 Jan 2021 17:38:33 +0200 Subject: [PATCH 2/5] ijar: fix manifest sections handling - add test jar --- .../ijar/test/jar-with-manifest-sections.jar | Bin 0 -> 3348 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 third_party/ijar/test/jar-with-manifest-sections.jar diff --git a/third_party/ijar/test/jar-with-manifest-sections.jar b/third_party/ijar/test/jar-with-manifest-sections.jar new file mode 100644 index 0000000000000000000000000000000000000000..4c652f32c1d84e2f80da5448d45c54a17e68086d GIT binary patch literal 3348 zcma)9c|4SD7aqo*ELpP;84P1=FnF-n${WwMo>WckWgLnz6T zk~K?~kI0fl67Q>Idx?_wk?$*7-g=(jx$l3T-*xW$oa>x(J?0oN11|^!VgU@I{eG21 z%cKW^oEbqNUXTb#k3{mK*i#5j1|IglzKV{UtEB}i2yA{{2V=wjz}nA$7l@9*=PVe+ zfImS83dRrNc=UL6vOK9u`XVSNZaN6{76YFEg8(YQmDfZ;ET{+F8(#p`p`kCpbTQ(g z`IcwTi4)FfvBuY-uzoM9pH;hWtgp;)o|As{vWl9H?7iGSka>O;DQTsY&_n5I(!stv zJx-VU(m&FeNle(kf$O=z2wY{b+F+`+t?H6?>l@gK)-XQmwYdE>!}NDig{?I~SQE1Y zCjMn^V{!&&*RRyKo3yR(9-tjPlVYzn@LIW_cz9Y0jy@{JIF_XM@;+Uo71t|Tc927n zKHJ}!kjyJXj*%YzM&y}J);8U~_A|2~WFge4E_vi^_QbBv%5ZMWJ;|qE?qflyyFsjK zaF1(pZWT!hjQUzG+;9QYVz5v2a`{?Lw;S4thRt2!(6VmlTajyWa?vog^z2u*y@421 zsGaHmNdJQOUU+R+p8zG4pQ_|>vcEx9yK;^mv6rdarS>=vDdEHLsf)u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O;o8(s*BOqJoGQI_iB?N-MVGcz_01s)MR z{51KbKiJsHE@|B1bo876K0SURK*NhlHqCZehoUVeFHNv1Dh%w6N)sDO9WHqyFnSek z8@D!NRj}S6v5!5_Vsn0(Ge(MQYv zImbse+#4ta6DkyP6I$Lc;)-mN%NIa*dxs}Ee-hqI5*yHMHXn%g*1ol}0!hLeS?Iyh zrUwyU#LS-W#mv_{zp>tjqyFa^1P36T1Z-0peSyI0nW7IG;Vl%g2S205jxL-?0BlPd zO@l!ohRtOW+wu4?2Cmq%8v}=Rb#&jsDfOw2O_CK&unK5wk6&RqPL>WWGj%<0fjm!M zm401dEtfYrwMed>oU)PIC(REDPuf%DUoEn@fKkE4T*ZODUa{(U@ZqMHy+%C1**1+G zI3I=JPjMy!#ZU34d_EUDaKj%+HoTW7L1Ob`2}dsyg+QYCvYBJ(=*7T4Q-y+ngRLj; z{O0~+jmWsA5x>!g-y-jv!rPJm0?O&@9QZPme-C!&sM!u{%di9XmxJf`{OxSU+x-;+ zLVDXZ_Wi6i|DK Date: Fri, 29 Jan 2021 10:25:14 +0200 Subject: [PATCH 3/5] Add ijar test when original MANIFEST contains target label and sections --- third_party/ijar/test/BUILD | 9 ++++++++ third_party/ijar/test/IjarTests.java | 21 ++++++++++++++++++ ...ith-target-label-and-manifest-sections.jar | Bin 0 -> 3371 bytes 3 files changed, 30 insertions(+) create mode 100644 third_party/ijar/test/jar-with-target-label-and-manifest-sections.jar diff --git a/third_party/ijar/test/BUILD b/third_party/ijar/test/BUILD index 3061fecc001e91..81eae07c8df67b 100644 --- a/third_party/ijar/test/BUILD +++ b/third_party/ijar/test/BUILD @@ -152,6 +152,14 @@ genrule( tools = ["//third_party/ijar"], ) +genrule( + name = "jar_with_target_label_and_manifest_sections", + srcs = ["jar-with-target-label-and-manifest-sections.jar"], + outs = ["jar-with-target-label-and-manifest-sections-nostrip.jar"], + cmd = "$(location //third_party/ijar) --target_label //foo:foo --nostrip_jar $< $@", + tools = ["//third_party/ijar"], +) + genrule( name = "jar_without_manifest_nostrip_idempotence", srcs = ["jar-without-manifest-nostrip.jar"], @@ -324,6 +332,7 @@ java_test( ":jar_with_manifest_and_target_label_nostrip", ":jar_with_manifest_nostrip", ":jar_with_manifest_sections", + ":jar_with_target_label_and_manifest_sections", ":jar_without_manifest_nostrip", ":jar_without_manifest_nostrip_idempotence", ":kotlin_module-interface.jar", diff --git a/third_party/ijar/test/IjarTests.java b/third_party/ijar/test/IjarTests.java index ecad9c3c712f57..fb42c337d27335 100644 --- a/third_party/ijar/test/IjarTests.java +++ b/third_party/ijar/test/IjarTests.java @@ -420,6 +420,27 @@ public void testPreserveManifestSections() throws Exception { } } + @Test + public void testPreserveManifestSectionsAndUpdateExistingTargetLabel() throws Exception { + try (JarFile stripped = new JarFile( + "third_party/ijar/test/jar-with-target-label-and-manifest-sections-nostrip.jar")) { + ImmutableList strippedEntries = + stripped.stream().map(JarEntry::getName).collect(toImmutableList()); + + assertThat(strippedEntries.get(0)).isEqualTo("META-INF/"); + assertThat(strippedEntries.get(1)).isEqualTo("META-INF/MANIFEST.MF"); + Manifest manifest = stripped.getManifest(); + Attributes attributes = manifest.getMainAttributes(); + assertThat(attributes.getValue("Target-Label")).isEqualTo("//foo:foo"); + + Attributes sectionAttributes1 = manifest.getAttributes("foo"); + assertThat(sectionAttributes1.getValue("Foo")).isEqualTo("bar"); + + Attributes sectionAttributes2 = manifest.getAttributes("baz"); + assertThat(sectionAttributes2.getValue("Another")).isEqualTo("bar"); + } + } + // Tests idempotence of --nostrip @Test public void testNoStripIdempotence() throws Exception { diff --git a/third_party/ijar/test/jar-with-target-label-and-manifest-sections.jar b/third_party/ijar/test/jar-with-target-label-and-manifest-sections.jar new file mode 100644 index 0000000000000000000000000000000000000000..007949fc268b72676bd8c527041a81af71cf8e6b GIT binary patch literal 3371 zcma)9c{o&U8z07=>>~S;$v(EwFqaui8j~eM5vsvpEQ2w!XP>0SPO@BOt0BZIOUf=w z;WLpXL|VLwY}rb_Bi~o_)?4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38:14 +0200 Subject: [PATCH 4/5] Add assertion on non manifest files --- third_party/ijar/test/IjarTests.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/third_party/ijar/test/IjarTests.java b/third_party/ijar/test/IjarTests.java index fb42c337d27335..2e9561049feb6c 100644 --- a/third_party/ijar/test/IjarTests.java +++ b/third_party/ijar/test/IjarTests.java @@ -401,8 +401,10 @@ public void testNoStripJarWithoutManifest() throws Exception { @Test public void testPreserveManifestSections() throws Exception { - try (JarFile stripped = new JarFile( - "third_party/ijar/test/jar-with-manifest-sections-nostrip.jar")) { + try (JarFile original = new JarFile( + "third_party/ijar/test/jar-with-target-label-and-manifest-sections-nostrip.jar"); + JarFile stripped = new JarFile( + "third_party/ijar/test/jar-with-manifest-sections-nostrip.jar")) { ImmutableList strippedEntries = stripped.stream().map(JarEntry::getName).collect(toImmutableList()); @@ -411,6 +413,7 @@ public void testPreserveManifestSections() throws Exception { Manifest manifest = stripped.getManifest(); Attributes attributes = manifest.getMainAttributes(); assertThat(attributes.getValue("Target-Label")).isEqualTo("//foo:foo"); + assertNonManifestFilesBitIdentical(original, stripped); Attributes sectionAttributes1 = manifest.getAttributes("foo"); assertThat(sectionAttributes1.getValue("Foo")).isEqualTo("bar"); @@ -422,8 +425,11 @@ public void testPreserveManifestSections() throws Exception { @Test public void testPreserveManifestSectionsAndUpdateExistingTargetLabel() throws Exception { - try (JarFile stripped = new JarFile( - "third_party/ijar/test/jar-with-target-label-and-manifest-sections-nostrip.jar")) { + try (JarFile original = new JarFile( + "third_party/ijar/test/jar-with-target-label-and-manifest-sections-nostrip.jar"); + JarFile stripped = new JarFile( + "third_party/ijar/test/jar-with-target-label-and-manifest-sections-nostrip.jar") + ) { ImmutableList strippedEntries = stripped.stream().map(JarEntry::getName).collect(toImmutableList()); @@ -432,6 +438,7 @@ public void testPreserveManifestSectionsAndUpdateExistingTargetLabel() throws Ex Manifest manifest = stripped.getManifest(); Attributes attributes = manifest.getMainAttributes(); assertThat(attributes.getValue("Target-Label")).isEqualTo("//foo:foo"); + assertNonManifestFilesBitIdentical(original, stripped); Attributes sectionAttributes1 = manifest.getAttributes("foo"); assertThat(sectionAttributes1.getValue("Foo")).isEqualTo("bar"); From 67edb6a9ac1081faf5f817cd9304dfff02efaff5 Mon Sep 17 00:00:00 2001 From: Vaidas Pilkauskas Date: Fri, 29 Jan 2021 21:43:16 +0200 Subject: [PATCH 5/5] Generate test input jars with manifest sections --- third_party/ijar/test/BUILD | 38 +++++++++-- .../ijar/test/GenJarWithManifestSections.java | 61 ++++++++++++++++++ .../ijar/test/jar-with-manifest-sections.jar | Bin 3348 -> 0 bytes ...ith-target-label-and-manifest-sections.jar | Bin 3371 -> 0 bytes 4 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 third_party/ijar/test/GenJarWithManifestSections.java delete mode 100644 third_party/ijar/test/jar-with-manifest-sections.jar delete mode 100644 third_party/ijar/test/jar-with-target-label-and-manifest-sections.jar diff --git a/third_party/ijar/test/BUILD b/third_party/ijar/test/BUILD index 81eae07c8df67b..2621c9b7cbf688 100644 --- a/third_party/ijar/test/BUILD +++ b/third_party/ijar/test/BUILD @@ -145,19 +145,21 @@ genrule( ) genrule( - name = "jar_with_manifest_sections", - srcs = ["jar-with-manifest-sections.jar"], + name = "jar_with_manifest_sections_nostrip", + srcs = [":jar_with_manifest_sections"], outs = ["jar-with-manifest-sections-nostrip.jar"], cmd = "$(location //third_party/ijar) --target_label //foo:foo --nostrip_jar $< $@", tools = ["//third_party/ijar"], + testonly = 1, ) genrule( - name = "jar_with_target_label_and_manifest_sections", - srcs = ["jar-with-target-label-and-manifest-sections.jar"], + name = "jar_with_target_label_and_manifest_sections_nostrip", + srcs = [":jar_with_target_label_and_manifest_sections"], outs = ["jar-with-target-label-and-manifest-sections-nostrip.jar"], cmd = "$(location //third_party/ijar) --target_label //foo:foo --nostrip_jar $< $@", tools = ["//third_party/ijar"], + testonly = 1, ) genrule( @@ -308,6 +310,30 @@ genrule( tools = ["//third_party/ijar"], ) +java_binary( + name = "GenJarWithManifestSections", + main_class = "GenJarWithManifestSections", + srcs = ["GenJarWithManifestSections.java"], + deps = ["//third_party:guava"], + testonly = 1, +) + +genrule( + name = "jar_with_manifest_sections", + outs = ["jar-with-manifest-sections.jar"], + cmd = "$(location :GenJarWithManifestSections) $@", + testonly = 1, + tools = [":GenJarWithManifestSections"], +) + +genrule( + name = "jar_with_target_label_and_manifest_sections", + outs = ["jar-with-target-label-and-manifest-sections.jar"], + cmd = "$(location :GenJarWithManifestSections) $@ //not:this", + testonly = 1, + tools = [":GenJarWithManifestSections"], +) + java_test( name = "IjarTests", size = "small", @@ -331,8 +357,8 @@ java_test( ":interface_ijar_testlib_with_target_label", ":jar_with_manifest_and_target_label_nostrip", ":jar_with_manifest_nostrip", - ":jar_with_manifest_sections", - ":jar_with_target_label_and_manifest_sections", + ":jar_with_manifest_sections_nostrip", + ":jar_with_target_label_and_manifest_sections_nostrip", ":jar_without_manifest_nostrip", ":jar_without_manifest_nostrip_idempotence", ":kotlin_module-interface.jar", diff --git a/third_party/ijar/test/GenJarWithManifestSections.java b/third_party/ijar/test/GenJarWithManifestSections.java new file mode 100644 index 00000000000000..276f82dda0dc40 --- /dev/null +++ b/third_party/ijar/test/GenJarWithManifestSections.java @@ -0,0 +1,61 @@ +// Copyright 2021 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import com.google.common.io.ByteStreams; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Map; +import java.util.jar.Attributes; +import java.util.jar.JarOutputStream; +import java.util.jar.Manifest; +import java.util.zip.ZipEntry; + +public class GenJarWithManifestSections { + + public static void main(String[] args) throws IOException { + try (JarOutputStream jos = new JarOutputStream(Files.newOutputStream(Paths.get(args[0])))) { + addEntry(jos, "META-INF/MANIFEST.MF"); + Manifest manifest = new Manifest(); + Attributes mainAttributes = manifest.getMainAttributes(); + mainAttributes.put(Attributes.Name.MANIFEST_VERSION, "1.0"); + + if (args.length > 1) { + String targetLabel = args[1]; + mainAttributes.put(new Attributes.Name("Target-Label"), targetLabel); + } + + Map entries = manifest.getEntries(); + + Attributes foo = new Attributes(); + foo.put(new Attributes.Name("Foo"), "bar"); + entries.put("foo", foo); + + Attributes baz = new Attributes(); + baz.put(new Attributes.Name("Another"), "bar"); + entries.put("baz", baz); + + manifest.write(jos); + + addEntry(jos, "java/lang/String.class"); + ByteStreams.copy(String.class.getResourceAsStream("/java/lang/String.class"), jos); + } + } + + private static void addEntry(JarOutputStream jos, String name) throws IOException { + ZipEntry ze = new ZipEntry(name); + ze.setTime(0); + jos.putNextEntry(ze); + } +} diff --git a/third_party/ijar/test/jar-with-manifest-sections.jar b/third_party/ijar/test/jar-with-manifest-sections.jar deleted file mode 100644 index 4c652f32c1d84e2f80da5448d45c54a17e68086d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3348 zcma)9c|4SD7aqo*ELpP;84P1=FnF-n${WwMo>WckWgLnz6T zk~K?~kI0fl67Q>Idx?_wk?$*7-g=(jx$l3T-*xW$oa>x(J?0oN11|^!VgU@I{eG21 z%cKW^oEbqNUXTb#k3{mK*i#5j1|IglzKV{UtEB}i2yA{{2V=wjz}nA$7l@9*=PVe+ zfImS83dRrNc=UL6vOK9u`XVSNZaN6{76YFEg8(YQmDfZ;ET{+F8(#p`p`kCpbTQ(g z`IcwTi4)FfvBuY-uzoM9pH;hWtgp;)o|As{vWl9H?7iGSka>O;DQTsY&_n5I(!stv zJx-VU(m&FeNle(kf$O=z2wY{b+F+`+t?H6?>l@gK)-XQmwYdE>!}NDig{?I~SQE1Y zCjMn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