[9.3.3] Update the embedded JDK to 25.0.5.1. (#32792)

Updates the embedded Azul Zulu 25 JDK archives on Linux (`x64`,
`aarch64`), macOS (`x64`, `aarch64`), and Windows (`x64`, `arm64`) to
`25.0.5.1` (`zulu25.38.201`) to address `CVE-2026-114938`. Non-x86
Adoptium Temurin 25 archives (`ppc64le`, `riscv64`, `s390x`) are
unaffected by the `x86-64` AVX-512 intrinsic bug and remain unchanged.

Also includes #29003 so `src/minimize_jdk.sh` handles the
`Contents/Home` archive layout in `zulu25.38.201` macOS archives, and
#32592 to fix `.ar` BSD long-name NUL padding /
`test_extract_non_readable_file_ar` on macOS 26 / Xcode 26.

RELNOTES: Updated the bundled JDK to 25.0.5.1.

(cherry picked from commit 535d6331d6f6378d791e633905e60a909789948b)
(cherry picked from commit 30789d19b83025d021dabece6d17565d9baec582)
(cherry picked from commit 01595c124be99235c0c99ded6bafddc1ef5b0b5d)

---------

Co-authored-by: Yun Peng <pcloudy@google.com>
diff --git a/MODULE.bazel b/MODULE.bazel
index d9b0cff..cec4ffc 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -359,7 +359,6 @@
     "openjdk_linux_vanilla",
     "openjdk_macos_aarch64_vanilla",
     "openjdk_macos_x86_64_vanilla",
-    "openjdk_win_arm64_jmods",
     "openjdk_win_arm64_vanilla",
     "openjdk_win_vanilla",
 )
diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock
index 368fa9d..6d552f7 100644
--- a/MODULE.bazel.lock
+++ b/MODULE.bazel.lock
@@ -372,7 +372,7 @@
   "moduleExtensions": {
     "//:repositories.bzl%async_profiler_repos": {
       "general": {
-        "bzlTransitiveDigest": "gH/iUxO5mMEg2qSMGUebcmcBn5Rfm9rJLLvaXAR4Oxs=",
+        "bzlTransitiveDigest": "eG2GxC9jRldZe0W/5jX4DwwAHqBwgklCcZF8hZaeMdQ=",
         "usagesDigest": "HZpweKHRMOtXoILBP5eDAiXnYrVp3ueoyGz39BVKgsg=",
         "recordedInputs": [
           "REPO_MAPPING:,async_profiler +async_profiler_repos+async_profiler",
diff --git a/repositories.bzl b/repositories.bzl
index 6817783..c93644c 100644
--- a/repositories.bzl
+++ b/repositories.bzl
@@ -81,15 +81,15 @@
     """OpenJDK distributions used to create a version of Bazel bundled with the OpenJDK."""
     http_file(
         name = "openjdk_linux_vanilla",
-        integrity = "sha256-8XUtAFG2yiM2Jd2ywYyRcO2+VcXuZRW/79jqAZfuHCA=",
+        integrity = "sha256-/Ho9k5a0QxNGZrnPfNlGtTLcF4H1NQxyWEmsUNFqcZg=",
         downloaded_file_path = "zulu-linux-vanilla.tar.gz",
-        url = "https://cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-linux_x64.tar.gz",
+        url = "https://cdn.azul.com/zulu/bin/zulu25.38.201-ca-jdk25.0.5.1-linux_x64.tar.gz",
     )
     http_file(
         name = "openjdk_linux_aarch64_vanilla",
-        integrity = "sha256-9ylaux3ssvbg6p92CnCRfy1HNW20Nm1hXHq5sBw8aGY=",
+        integrity = "sha256-fww1aBPeMV26xE0aKi1hpcq51qyPLN/24yyZS+XALaE=",
         downloaded_file_path = "zulu-linux-aarch64-vanilla.tar.gz",
-        url = "https://cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-linux_aarch64.tar.gz",
+        url = "https://cdn.azul.com/zulu/bin/zulu25.38.201-ca-jdk25.0.5.1-linux_aarch64.tar.gz",
     )
     http_file(
         name = "openjdk_linux_ppc64le_vanilla",
@@ -111,41 +111,27 @@
     )
     http_file(
         name = "openjdk_macos_x86_64_vanilla",
-        integrity = "sha256-/iI0bBkpIMW4SyP0qiTj3rsLuU/EKAFvfCssd5DIJ4A=",
+        integrity = "sha256-P3O3ynBCXXn7nFxpe5IkhzGhPUP/ltQbx0pWd44l6EY=",
         downloaded_file_path = "zulu-macos-vanilla.tar.gz",
-        url = "https://cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-macosx_x64.tar.gz",
+        url = "https://cdn.azul.com/zulu/bin/zulu25.38.201-ca-jdk25.0.5.1-macosx_x64.tar.gz",
     )
     http_file(
         name = "openjdk_macos_aarch64_vanilla",
-        integrity = "sha256-U3rHT6HKLE3Y9gY93t4BOK5KiW8Si/4QtCin3MSqkp8=",
+        integrity = "sha256-JJ1WDVBwP3GufE+QyHKm6caR5iB4RXhtWxj9KNMLj6M=",
         downloaded_file_path = "zulu-macos-aarch64-vanilla.tar.gz",
-        url = "https://cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-macosx_aarch64.tar.gz",
+        url = "https://cdn.azul.com/zulu/bin/zulu25.38.201-ca-jdk25.0.5.1-macosx_aarch64.tar.gz",
     )
     http_file(
         name = "openjdk_win_vanilla",
-        integrity = "sha256-kLy7y+L7euxDzo/S76Ak/MSPALvc16drWPkS1rl+bVY=",
+        integrity = "sha256-AcHEz+jA4EoipG080d3Ri525+yobCoj/2Q4KpXQghF4=",
         downloaded_file_path = "zulu-win-vanilla.zip",
-        url = "https://cdn.azul.com/zulu/bin/zulu25.32.17-ca-jdk25.0.2-win_x64.zip",
+        url = "https://cdn.azul.com/zulu/bin/zulu25.38.201-ca-jdk25.0.5.1-win_x64.zip",
     )
     http_file(
         name = "openjdk_win_arm64_vanilla",
-        integrity = "sha256-zhWbTuPBCc1RNXrPhCZBQsHdsOGHjSBGbqxQsBU0cVQ=",
+        integrity = "sha256-w3d43p5LuwWqU1clGzZDDjccPtABeE83kv5M1N78790=",
         downloaded_file_path = "zulu-win-arm64.zip",
-        # Use an EA release of 25.0.3 here since versions <= 25.0.2 are affected by a severe JDK bug
-        # that causes virtual threads (and thus repo rules) to hang indefinitely on Windows ARM64.
-        # https://github.com/bazelbuild/bazel/issues/28520
-        # https://mail.openjdk.org/pipermail/loom-dev/2026-February/008286.html
-        url = "https://github.com/adoptium/temurin25-binaries/releases/download/jdk-25.0.3%2B1-ea-beta/OpenJDK25U-jdk_aarch64_windows_hotspot_25.0.3_1-ea.zip",
-    )
-
-    # The Adoptium Temurin JDK above has JEP 493 enabled, which means it does not ship with jmods.
-    # These are needed for cross-jlinking (minimizing the JDK on a different platform).
-    # https://adoptium.net/news/2025/08/eclipse-temurin-jdk24-JEP493-enabled
-    http_file(
-        name = "openjdk_win_arm64_jmods",
-        integrity = "sha256-2rjwZCoUIYD7L9nLwLJindsYPkDMvpI4km5a9UlxFtg=",
-        downloaded_file_path = "temurin-win-arm64-jmods.zip",
-        url = "https://github.com/adoptium/temurin25-binaries/releases/download/jdk-25.0.3%2B1-ea-beta/OpenJDK25U-jmods_aarch64_windows_hotspot_25.0.3_1-ea.zip",
+        url = "https://cdn.azul.com/zulu/bin/zulu25.38.201-ca-jdk25.0.5.1-win_aarch64.zip",
     )
 
 def _async_profiler_repos(ctx):
diff --git a/src/BUILD b/src/BUILD
index fe4891e..b95516d 100644
--- a/src/BUILD
+++ b/src/BUILD
@@ -227,15 +227,9 @@
     srcs = [
         ":embedded_jdk_vanilla",
         ":jdeps_modules.golden",
-    ] + select({
-        "//src/conditions:windows_arm64": ["@openjdk_win_arm64_jmods//file"],
-        "//conditions:default": [],
-    }),
+    ],
     outs = ["minimal_jdk.zip"],
-    cmd = "$(location :minimize_jdk) $(location :jdk_for_jlink) $(location :embedded_jdk_vanilla) $(location :jdeps_modules.golden) $@" + select({
-        "//src/conditions:windows_arm64": " $(location @openjdk_win_arm64_jmods//file)",
-        "//conditions:default": "",
-    }),
+    cmd = "$(location :minimize_jdk) $(location :jdk_for_jlink) $(location :embedded_jdk_vanilla) $(location :jdeps_modules.golden) $@",
     tools = [
         ":jdk_for_jlink",
         ":minimize_jdk",
@@ -248,15 +242,9 @@
     srcs = [
         ":embedded_jdk_vanilla",
         ":jdeps_modules.golden",
-    ] + select({
-        "//src/conditions:windows_arm64": ["@openjdk_win_arm64_jmods//file"],
-        "//conditions:default": [],
-    }),
+    ],
     outs = ["allmodules_jdk.zip"],
-    cmd = "$(location :minimize_jdk) --allmodules $(location :jdk_for_jlink) $(location :embedded_jdk_vanilla) $(location :jdeps_modules.golden) $@" + select({
-        "//src/conditions:windows_arm64": " $(location @openjdk_win_arm64_jmods//file)",
-        "//conditions:default": "",
-    }),
+    cmd = "$(location :minimize_jdk) --allmodules $(location :jdk_for_jlink) $(location :embedded_jdk_vanilla) $(location :jdeps_modules.golden) $@",
     tools = [
         ":jdk_for_jlink",
         ":minimize_jdk",
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/decompressor/ArFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/decompressor/ArFunction.java
index e76835c..50976d4 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/decompressor/ArFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/decompressor/ArFunction.java
@@ -14,6 +14,7 @@
 
 package com.google.devtools.build.lib.bazel.repository.decompressor;
 
+import com.google.common.base.CharMatcher;
 import com.google.devtools.build.lib.bazel.repository.decompressor.DecompressorValue.Decompressor;
 import com.google.devtools.build.lib.vfs.Path;
 import java.io.BufferedInputStream;
@@ -49,7 +50,9 @@
       ArArchiveInputStream arStream = new ArArchiveInputStream(decompressorStream);
       ArArchiveEntry entry;
       while ((entry = arStream.getNextArEntry()) != null) {
-        String entryName = entry.getName();
+        // BSD ar (used on macOS) pads long names ("#1/<len>") with NUL bytes, for example
+        // "__.SYMDEF SORTED\0\0\0\0". Remove the padding.
+        String entryName = CharMatcher.is('\0').trimTrailingFrom(entry.getName());
         entryName = renameFiles.getOrDefault(entryName, entryName);
         Path filePath = descriptor.destinationPath().getRelative(entryName);
         filePath.getParentDirectory().createDirectoryAndParents();
diff --git a/src/minimize_jdk.sh b/src/minimize_jdk.sh
index fa652ce..d7dd732 100755
--- a/src/minimize_jdk.sh
+++ b/src/minimize_jdk.sh
@@ -97,12 +97,36 @@
   done
 }
 
+# Strips an extracted JDK archive to its home directory.
+# Some JDK archives (e.g., macOS .jdk bundles) nest the JDK home inside
+# additional directories like Contents/Home/. This function detects the
+# actual JDK home by locating the 'release' file and moves it to the
+# expected top-level directory.
+strip_to_jdk_home() {
+  local dir=$1
+  local release
+  release=$(find "$dir" -name release -maxdepth 4 -print -quit)
+  if [[ -z "$release" ]]; then
+    echo "ERROR: could not find 'release' file in $dir" >&2
+    exit 1
+  fi
+  local jdk_home
+  jdk_home=$(dirname "$release")
+  if [[ "$jdk_home" != "$dir" ]]; then
+    local tmp="${dir}_tmp"
+    mv "$jdk_home" "$tmp"
+    rm -rf "$dir"
+    mv "$tmp" "$dir"
+  fi
+}
+
 if [[ "$UNAME" =~ msys_nt* ]]; then
   unzip -q "$tooljdk" -d "tool_jdk.$$"
+  strip_to_jdk_home "tool_jdk.$$"
   unzip -q "$fulljdk" -d "full_jdk.$$"
-  # The archives contain a single top-level directory.
-  tool_jdk_home=$(cd tool_jdk.$$/* && pwd)
-  cd full_jdk.$$/*
+  strip_to_jdk_home "full_jdk.$$"
+  tool_jdk_home=$(cd "tool_jdk.$$" && pwd)
+  cd "full_jdk.$$"
   # If the full JDK doesn't ship with jmods (e.g. JEP 493), use the separately
   # provided jmods archive.
   if [ ! -f jmods/java.base.jmod ]; then
@@ -143,18 +167,20 @@
   # These are necessary for --host_jvm_debug to work.
   cp bin/dt_socket.dll bin/jdwp.dll reduced/bin
   zip -q -X -r ../reduced.zip reduced/
-  cd ../..
-  mv "full_jdk.$$/reduced.zip" "$out"
+  cd ..
+  mv reduced.zip "$out"
   rm -rf "full_jdk.$$" "tool_jdk.$$"
 else
   # The --no-same-owner flag instructs tar to not try to chown extracted files
   # to the owner stored in the archive - it will try to do that when running as
   # root, but fail when running inside Docker, so we explicitly disable it.
-  mkdir tool_jdk
-  tar xf "$tooljdk" --no-same-owner --strip-components=1 -C tool_jdk
-  mkdir target_jdk
-  tar xf "$fulljdk" --no-same-owner --strip-components=1 -C target_jdk
-  cd target_jdk
+  mkdir "tool_jdk.$$"
+  tar xf "$tooljdk" --no-same-owner -C "tool_jdk.$$"
+  strip_to_jdk_home "tool_jdk.$$"
+  mkdir "target_jdk.$$"
+  tar xf "$fulljdk" --no-same-owner -C "target_jdk.$$"
+  strip_to_jdk_home "target_jdk.$$"
+  cd "target_jdk.$$"
   # If the full JDK doesn't ship with jmods (e.g. JEP 493), use the separately
   # provided jmods archive.
   if [ ! -f jmods/java.base.jmod ]; then
@@ -169,11 +195,11 @@
       exit 1
     fi
   fi
-  "../tool_jdk/bin/jlink" --module-path ./jmods/ --add-modules "$modules" \
+  "../tool_jdk.$$/bin/jlink" --module-path ./jmods/ --add-modules "$modules" \
     --vm=server --strip-debug --no-man-pages --no-header-files \
     --add-options=" ${JVM_OPTIONS}" \
     --output reduced
-  remove_distrusted_certs "../tool_jdk/bin/keytool"
+  remove_distrusted_certs "../tool_jdk.$$/bin/keytool"
   for f in DISCLAIMER readme.txt legal/java.base/ASSEMBLY_EXCEPTION; do [ -f "$f" ] && cp "$f" reduced/; done
   # These are necessary for --host_jvm_debug to work.
   cp lib/libdt_socket.* lib/libjdwp.* reduced/lib
@@ -181,4 +207,5 @@
   zip -q -X -r ../reduced.zip reduced/
   cd ..
   mv reduced.zip "$out"
+  rm -rf "target_jdk.$$" "tool_jdk.$$"
 fi
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/repository/decompressor/ArFunctionTest.java b/src/test/java/com/google/devtools/build/lib/bazel/repository/decompressor/ArFunctionTest.java
index f8bf1d4..89d3b4d 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/repository/decompressor/ArFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/repository/decompressor/ArFunctionTest.java
@@ -15,6 +15,7 @@
 package com.google.devtools.build.lib.bazel.repository.decompressor;
 
 import static com.google.common.truth.Truth.assertThat;
+import static java.nio.charset.StandardCharsets.UTF_8;
 
 import com.google.devtools.build.lib.testutil.TestConstants;
 import com.google.devtools.build.lib.testutil.TestUtils;
@@ -24,17 +25,22 @@
 import com.google.devtools.build.lib.vfs.FileSystem;
 import com.google.devtools.build.lib.vfs.JavaIoFileSystem;
 import com.google.devtools.build.lib.vfs.Path;
+import com.google.devtools.build.lib.vfs.util.FileSystems;
 import com.google.devtools.build.runfiles.Runfiles;
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.HashMap;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
 
 /** Tests decompressing archives. */
 @RunWith(JUnit4.class)
 public class ArFunctionTest {
+  @Rule public TemporaryFolder folder = new TemporaryFolder();
   /*
    * .ar archive created with ar cr test_files.ar archived_first.txt archived_second.md
    * The files contain short UTF-8 encoded strings.
@@ -83,6 +89,49 @@
     return new ArFunction().decompress(descriptor);
   }
 
+  /**
+   * Test decompressing a BSD ar archive (as created by the macOS ar and ranlib) with long names
+   * ("#1/len") that are padded with NUL bytes.
+   */
+  @Test
+  public void testDecompressBsdLongNamesWithNulPadding() throws Exception {
+    FileSystem fs = FileSystems.getNativeFileSystem();
+    File arFile = folder.newFile("bsd.ar");
+    try (FileOutputStream out = new FileOutputStream(arFile)) {
+      out.write("!<arch>\n".getBytes(UTF_8));
+      writeBsdLongNameMember(out, "__.SYMDEF SORTED\0\0\0\0", new byte[8]);
+      writeBsdLongNameMember(out, "a_long_object_name.o\0\0\0\0", "content".getBytes(UTF_8));
+    }
+    Path arPath = fs.getPath(arFile.getAbsolutePath());
+    Path outDir = arPath.getParentDirectory().getRelative("out");
+
+    Path outputDir =
+        decompress(
+            DecompressorDescriptor.builder()
+                .setArchivePath(arPath)
+                .setDestinationPath(outDir)
+                .build());
+
+    assertThat(outputDir.getRelative("__.SYMDEF SORTED").exists()).isTrue();
+    Path objectFile = outputDir.getRelative("a_long_object_name.o");
+    assertThat(objectFile.exists()).isTrue();
+    assertThat(objectFile.getFileSize()).isEqualTo(7);
+  }
+
+  private static void writeBsdLongNameMember(FileOutputStream out, String name, byte[] data)
+      throws IOException {
+    int size = name.length() + data.length;
+    String header =
+        String.format(
+            "%-16s%-12s%-6s%-6s%-8s%-10s`\n", "#1/" + name.length(), "0", "0", "0", "644", size);
+    out.write(header.getBytes(UTF_8));
+    out.write(name.getBytes(UTF_8));
+    out.write(data);
+    if (size % 2 != 0) {
+      out.write('\n');
+    }
+  }
+
   private DecompressorDescriptor.Builder createDescriptorBuilder() throws IOException {
     // This was cribbed from TestArchiveDescriptor
     FileSystem testFS =
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/repository/decompressor/BUILD b/src/test/java/com/google/devtools/build/lib/bazel/repository/decompressor/BUILD
index a173973..97fb2bd 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/repository/decompressor/BUILD
+++ b/src/test/java/com/google/devtools/build/lib/bazel/repository/decompressor/BUILD
@@ -34,6 +34,7 @@
         "//src/test/java/com/google/devtools/build/lib/testutil",
         "//src/test/java/com/google/devtools/build/lib/testutil:TestConstants",
         "//src/test/java/com/google/devtools/build/lib/testutil:TestUtils",
+        "//src/test/java/com/google/devtools/build/lib/vfs/util",
         "//third_party:apache_commons_compress",
         "//third_party:guava",
         "//third_party:java-diff-utils",
diff --git a/src/test/shell/bazel/starlark_repository_test.sh b/src/test/shell/bazel/starlark_repository_test.sh
index 12f07e5..8a0bb86 100755
--- a/src/test/shell/bazel/starlark_repository_test.sh
+++ b/src/test/shell/bazel/starlark_repository_test.sh
@@ -3898,20 +3898,17 @@
 function test_extract_non_readable_file_ar() {
   local archive_ar="${TEST_TMPDIR}/non_readable.ar"
 
-  # Create a valid AR file, then patch the permission field to 0000
-  pushd "${TEST_TMPDIR}"
-  echo "secret ar content" > non_readable.txt
-  ar rc non_readable.ar non_readable.txt
-  # Patch the mode field (bytes 40-47 after the 8-byte magic) to "0       "
+  # Write the AR file directly. Do not use the system "ar": on macOS with
+  # Xcode 26, "ar" runs ranlib, which drops members that are not Mach-O files.
   python3 -c "
-with open('non_readable.ar', 'r+b') as f:
-    # AR magic is 8 bytes, then header starts
-    # Header format: filename(16) + mtime(12) + owner(6) + group(6) + mode(8) + size(10) + magic(2)
-    # Mode is at offset 8 + 16 + 12 + 6 + 6 = 48
-    f.seek(48)
-    f.write(b'0       ')  # 8 bytes for mode 0000 in octal
+data = b'secret ar content\\n'
+# Header: name(16) mtime(12) uid(6) gid(6) mode(8, octal) size(10) magic(2).
+header = (b'non_readable.txt'.ljust(16) + b'0'.ljust(12) + b'0'.ljust(6) +
+          b'0'.ljust(6) + b'0'.ljust(8) + str(len(data)).encode().ljust(10) +
+          b'\\x60\\n')
+with open('${archive_ar}', 'wb') as f:
+    f.write(b'!<arch>\\n' + header + data + b'\\n' * (len(data) % 2))
 "
-  popd
 
   _run_extract_test "${archive_ar}" "non_readable.txt" "secret ar content"
 }