Copilot commented on code in PR #13669:
URL: https://github.com/apache/gluten/pull/13669#discussion_r4648649356
##########
build/mvn:
##########
@@ -67,6 +71,32 @@ download_mvn() {
return 1
}
+verify_mvn() {
+ local ARCHIVE="$1" CHECKSUM_FILE="$2" CHECKSUM
+ local SHA512
+ if command -v sha512sum > /dev/null 2>&1; then
+ SHA512=(sha512sum)
+ elif command -v shasum > /dev/null 2>&1; then
+ SHA512=(shasum -a 512)
+ else
+ echo "ERROR: Neither sha512sum nor shasum found. Install one to verify
the Maven distribution." >&2
+ return 1
+ fi
+
+ # Apache publishes a bare SHA-512 digest, not a checksum-tool manifest.
+ if ! CHECKSUM=$(tr -d '[:space:]' < "$CHECKSUM_FILE") ||
+ ! [[ "$CHECKSUM" =~ ^[0-9a-fA-F]{128}$ ]]; then
+ echo "ERROR: Invalid SHA-512 checksum in ${CHECKSUM_FILE}" >&2
+ return 1
+ fi
+ # Keep checkout paths out of the line-based checksum manifest.
+ if ! printf '%s %s\n' "$CHECKSUM" "${ARCHIVE##*/}" |
+ (cd "${ARCHIVE%/*}" && "${SHA512[@]}" -c -) >&2; then
Review Comment:
`cd "${ARCHIVE%/*}"` breaks when `ARCHIVE` has no `/` (because
`${ARCHIVE%/*}` expands to the full filename, causing `cd` to fail). Even if
current callers pass a path containing a directory, making this robust avoids a
sharp edge for future reuse. A common pattern is to compute
`archive_dir=${ARCHIVE%/*}` and fall back to `.` when it equals the original
archive string (or use `dirname`).
##########
build/mvn:
##########
@@ -100,32 +130,56 @@ install_mvn() {
echo "Maven ${VERSION} not found locally. Downloading..." >&2
# Create download directory
- mkdir -p "${MVN_DOWNLOAD_DIR}"
+ mkdir -p "${MVN_DOWNLOAD_DIR}" || exit 1
local MVN_TAR="${MVN_DOWNLOAD_DIR}/apache-maven-${VERSION}-bin.tar.gz"
+ local MVN_SHA512="${MVN_TAR}.sha512"
+ local
DISTRIBUTION_PATH="maven/maven-${VERSION%%.*}/${VERSION}/binaries/apache-maven-${VERSION}-bin.tar.gz"
+ local SOURCE DOWNLOAD_URL CHECKSUM_URL VERIFIED=false
+ # A missing checksum is not a reason to discard a pre-existing archive.
+ local DOWNLOAD_FILES=("$MVN_SHA512")
+ if [ ! -f "$MVN_TAR" ]; then
+ DOWNLOAD_FILES+=("$MVN_TAR")
+ fi
- if [ ! -f "${MVN_TAR}" ]; then
- # Use Maven Central repository for download
- local
DOWNLOAD_URL="https://repo1.maven.org/maven2/org/apache/maven/apache-maven/${VERSION}/apache-maven-${VERSION}-bin.tar.gz"
+ for SOURCE in https://dlcdn.apache.org
https://archive.apache.org/dist; do
+ DOWNLOAD_URL="${SOURCE}/${DISTRIBUTION_PATH}"
+ CHECKSUM_URL="${DOWNLOAD_URL}.sha512"
+ if [ "$SOURCE" = https://dlcdn.apache.org ]; then
+
CHECKSUM_URL="https://downloads.apache.org/${DISTRIBUTION_PATH}.sha512"
+ fi
- echo "Downloading Maven ${VERSION} from Maven Central..." >&2
echo "URL: ${DOWNLOAD_URL}" >&2
+ if { [ -f "$MVN_TAR" ] || download_mvn "$DOWNLOAD_URL" "$MVN_TAR";
} &&
+ download_mvn "$CHECKSUM_URL" "$MVN_SHA512"; then
+ if ! verify_mvn "$MVN_TAR" "$MVN_SHA512"; then
+ rm -f "$MVN_TAR" "$MVN_SHA512"
Review Comment:
The new `rm` and `tar` invocations should defensively use `--` before path
arguments to prevent option injection if any computed path ever begins with `-`
(e.g., from an overridden directory variable). For example: `rm -f -- ...` and
`tar -xzf -- ...`. This aligns with the PR goal of avoiding path interpretation
as options.
##########
build/mvn:
##########
@@ -100,32 +130,56 @@ install_mvn() {
echo "Maven ${VERSION} not found locally. Downloading..." >&2
# Create download directory
- mkdir -p "${MVN_DOWNLOAD_DIR}"
+ mkdir -p "${MVN_DOWNLOAD_DIR}" || exit 1
local MVN_TAR="${MVN_DOWNLOAD_DIR}/apache-maven-${VERSION}-bin.tar.gz"
+ local MVN_SHA512="${MVN_TAR}.sha512"
+ local
DISTRIBUTION_PATH="maven/maven-${VERSION%%.*}/${VERSION}/binaries/apache-maven-${VERSION}-bin.tar.gz"
+ local SOURCE DOWNLOAD_URL CHECKSUM_URL VERIFIED=false
+ # A missing checksum is not a reason to discard a pre-existing archive.
+ local DOWNLOAD_FILES=("$MVN_SHA512")
+ if [ ! -f "$MVN_TAR" ]; then
+ DOWNLOAD_FILES+=("$MVN_TAR")
+ fi
- if [ ! -f "${MVN_TAR}" ]; then
- # Use Maven Central repository for download
- local
DOWNLOAD_URL="https://repo1.maven.org/maven2/org/apache/maven/apache-maven/${VERSION}/apache-maven-${VERSION}-bin.tar.gz"
+ for SOURCE in https://dlcdn.apache.org
https://archive.apache.org/dist; do
+ DOWNLOAD_URL="${SOURCE}/${DISTRIBUTION_PATH}"
+ CHECKSUM_URL="${DOWNLOAD_URL}.sha512"
+ if [ "$SOURCE" = https://dlcdn.apache.org ]; then
+
CHECKSUM_URL="https://downloads.apache.org/${DISTRIBUTION_PATH}.sha512"
+ fi
- echo "Downloading Maven ${VERSION} from Maven Central..." >&2
echo "URL: ${DOWNLOAD_URL}" >&2
+ if { [ -f "$MVN_TAR" ] || download_mvn "$DOWNLOAD_URL" "$MVN_TAR";
} &&
+ download_mvn "$CHECKSUM_URL" "$MVN_SHA512"; then
Review Comment:
`download_mvn`’s error/retry messages are Maven-specific (e.g., “Failed to
download Maven…”, “Maven download attempt…”). With this change, the same
function is now also used for downloading the `.sha512` file, so failures will
misleadingly report that Maven (the tarball) failed to download even when only
the checksum fetch failed. Consider making `download_mvn` accept a label (e.g.,
“Maven archive” vs “Maven checksum”) or adjusting its messages to be
URL/resource-generic so logs stay accurate.
##########
build/mvn:
##########
@@ -100,32 +130,56 @@ install_mvn() {
echo "Maven ${VERSION} not found locally. Downloading..." >&2
# Create download directory
- mkdir -p "${MVN_DOWNLOAD_DIR}"
+ mkdir -p "${MVN_DOWNLOAD_DIR}" || exit 1
local MVN_TAR="${MVN_DOWNLOAD_DIR}/apache-maven-${VERSION}-bin.tar.gz"
+ local MVN_SHA512="${MVN_TAR}.sha512"
+ local
DISTRIBUTION_PATH="maven/maven-${VERSION%%.*}/${VERSION}/binaries/apache-maven-${VERSION}-bin.tar.gz"
+ local SOURCE DOWNLOAD_URL CHECKSUM_URL VERIFIED=false
+ # A missing checksum is not a reason to discard a pre-existing archive.
+ local DOWNLOAD_FILES=("$MVN_SHA512")
+ if [ ! -f "$MVN_TAR" ]; then
+ DOWNLOAD_FILES+=("$MVN_TAR")
+ fi
- if [ ! -f "${MVN_TAR}" ]; then
- # Use Maven Central repository for download
- local
DOWNLOAD_URL="https://repo1.maven.org/maven2/org/apache/maven/apache-maven/${VERSION}/apache-maven-${VERSION}-bin.tar.gz"
+ for SOURCE in https://dlcdn.apache.org
https://archive.apache.org/dist; do
+ DOWNLOAD_URL="${SOURCE}/${DISTRIBUTION_PATH}"
+ CHECKSUM_URL="${DOWNLOAD_URL}.sha512"
+ if [ "$SOURCE" = https://dlcdn.apache.org ]; then
+
CHECKSUM_URL="https://downloads.apache.org/${DISTRIBUTION_PATH}.sha512"
+ fi
- echo "Downloading Maven ${VERSION} from Maven Central..." >&2
echo "URL: ${DOWNLOAD_URL}" >&2
+ if { [ -f "$MVN_TAR" ] || download_mvn "$DOWNLOAD_URL" "$MVN_TAR";
} &&
+ download_mvn "$CHECKSUM_URL" "$MVN_SHA512"; then
+ if ! verify_mvn "$MVN_TAR" "$MVN_SHA512"; then
+ rm -f "$MVN_TAR" "$MVN_SHA512"
+ exit 1
+ fi
+ VERIFIED=true
+ break
+ fi
- download_mvn "$DOWNLOAD_URL" "$MVN_TAR" || exit 1
+ rm -f "${DOWNLOAD_FILES[@]}"
Review Comment:
The new `rm` and `tar` invocations should defensively use `--` before path
arguments to prevent option injection if any computed path ever begins with `-`
(e.g., from an overridden directory variable). For example: `rm -f -- ...` and
`tar -xzf -- ...`. This aligns with the PR goal of avoiding path interpretation
as options.
##########
build/mvn:
##########
@@ -100,32 +130,56 @@ install_mvn() {
echo "Maven ${VERSION} not found locally. Downloading..." >&2
# Create download directory
- mkdir -p "${MVN_DOWNLOAD_DIR}"
+ mkdir -p "${MVN_DOWNLOAD_DIR}" || exit 1
local MVN_TAR="${MVN_DOWNLOAD_DIR}/apache-maven-${VERSION}-bin.tar.gz"
+ local MVN_SHA512="${MVN_TAR}.sha512"
+ local
DISTRIBUTION_PATH="maven/maven-${VERSION%%.*}/${VERSION}/binaries/apache-maven-${VERSION}-bin.tar.gz"
+ local SOURCE DOWNLOAD_URL CHECKSUM_URL VERIFIED=false
+ # A missing checksum is not a reason to discard a pre-existing archive.
+ local DOWNLOAD_FILES=("$MVN_SHA512")
+ if [ ! -f "$MVN_TAR" ]; then
+ DOWNLOAD_FILES+=("$MVN_TAR")
+ fi
- if [ ! -f "${MVN_TAR}" ]; then
- # Use Maven Central repository for download
- local
DOWNLOAD_URL="https://repo1.maven.org/maven2/org/apache/maven/apache-maven/${VERSION}/apache-maven-${VERSION}-bin.tar.gz"
+ for SOURCE in https://dlcdn.apache.org
https://archive.apache.org/dist; do
+ DOWNLOAD_URL="${SOURCE}/${DISTRIBUTION_PATH}"
+ CHECKSUM_URL="${DOWNLOAD_URL}.sha512"
+ if [ "$SOURCE" = https://dlcdn.apache.org ]; then
+
CHECKSUM_URL="https://downloads.apache.org/${DISTRIBUTION_PATH}.sha512"
+ fi
- echo "Downloading Maven ${VERSION} from Maven Central..." >&2
echo "URL: ${DOWNLOAD_URL}" >&2
+ if { [ -f "$MVN_TAR" ] || download_mvn "$DOWNLOAD_URL" "$MVN_TAR";
} &&
+ download_mvn "$CHECKSUM_URL" "$MVN_SHA512"; then
+ if ! verify_mvn "$MVN_TAR" "$MVN_SHA512"; then
+ rm -f "$MVN_TAR" "$MVN_SHA512"
+ exit 1
+ fi
+ VERIFIED=true
+ break
+ fi
- download_mvn "$DOWNLOAD_URL" "$MVN_TAR" || exit 1
+ rm -f "${DOWNLOAD_FILES[@]}"
+ if [ "$SOURCE" = https://dlcdn.apache.org ]; then
+ echo "WARNING: Maven distribution or checksum unavailable;
trying the Apache archive..." >&2
+ fi
+ done
- echo "Download completed successfully" >&2
+ if [ "$VERIFIED" != true ]; then
+ echo "ERROR: Failed to download Maven ${VERSION} and its SHA-512
checksum from Apache." >&2
+ exit 1
fi
- # Extract Maven
+ # GNU tar interprets backslash escapes in -C paths.
echo "Extracting Maven to ${MVN_DOWNLOAD_DIR}..." >&2
- if ! tar -xzf "${MVN_TAR}" -C "${MVN_DOWNLOAD_DIR}"; then
+ if ! (cd "${MVN_DOWNLOAD_DIR}" && tar -xzf "${MVN_TAR##*/}"); then
echo "ERROR: Failed to extract Maven" >&2
- rm -f "${MVN_TAR}"
+ rm -f "$MVN_TAR" "$MVN_SHA512"
Review Comment:
The new `rm` and `tar` invocations should defensively use `--` before path
arguments to prevent option injection if any computed path ever begins with `-`
(e.g., from an overridden directory variable). For example: `rm -f -- ...` and
`tar -xzf -- ...`. This aligns with the PR goal of avoiding path interpretation
as options.
##########
build/mvn:
##########
@@ -100,32 +130,56 @@ install_mvn() {
echo "Maven ${VERSION} not found locally. Downloading..." >&2
# Create download directory
- mkdir -p "${MVN_DOWNLOAD_DIR}"
+ mkdir -p "${MVN_DOWNLOAD_DIR}" || exit 1
local MVN_TAR="${MVN_DOWNLOAD_DIR}/apache-maven-${VERSION}-bin.tar.gz"
+ local MVN_SHA512="${MVN_TAR}.sha512"
+ local
DISTRIBUTION_PATH="maven/maven-${VERSION%%.*}/${VERSION}/binaries/apache-maven-${VERSION}-bin.tar.gz"
+ local SOURCE DOWNLOAD_URL CHECKSUM_URL VERIFIED=false
+ # A missing checksum is not a reason to discard a pre-existing archive.
+ local DOWNLOAD_FILES=("$MVN_SHA512")
+ if [ ! -f "$MVN_TAR" ]; then
+ DOWNLOAD_FILES+=("$MVN_TAR")
+ fi
- if [ ! -f "${MVN_TAR}" ]; then
- # Use Maven Central repository for download
- local
DOWNLOAD_URL="https://repo1.maven.org/maven2/org/apache/maven/apache-maven/${VERSION}/apache-maven-${VERSION}-bin.tar.gz"
+ for SOURCE in https://dlcdn.apache.org
https://archive.apache.org/dist; do
+ DOWNLOAD_URL="${SOURCE}/${DISTRIBUTION_PATH}"
+ CHECKSUM_URL="${DOWNLOAD_URL}.sha512"
+ if [ "$SOURCE" = https://dlcdn.apache.org ]; then
+
CHECKSUM_URL="https://downloads.apache.org/${DISTRIBUTION_PATH}.sha512"
+ fi
- echo "Downloading Maven ${VERSION} from Maven Central..." >&2
echo "URL: ${DOWNLOAD_URL}" >&2
+ if { [ -f "$MVN_TAR" ] || download_mvn "$DOWNLOAD_URL" "$MVN_TAR";
} &&
+ download_mvn "$CHECKSUM_URL" "$MVN_SHA512"; then
+ if ! verify_mvn "$MVN_TAR" "$MVN_SHA512"; then
+ rm -f "$MVN_TAR" "$MVN_SHA512"
+ exit 1
+ fi
+ VERIFIED=true
+ break
+ fi
- download_mvn "$DOWNLOAD_URL" "$MVN_TAR" || exit 1
+ rm -f "${DOWNLOAD_FILES[@]}"
+ if [ "$SOURCE" = https://dlcdn.apache.org ]; then
+ echo "WARNING: Maven distribution or checksum unavailable;
trying the Apache archive..." >&2
+ fi
+ done
- echo "Download completed successfully" >&2
+ if [ "$VERIFIED" != true ]; then
+ echo "ERROR: Failed to download Maven ${VERSION} and its SHA-512
checksum from Apache." >&2
+ exit 1
fi
- # Extract Maven
+ # GNU tar interprets backslash escapes in -C paths.
echo "Extracting Maven to ${MVN_DOWNLOAD_DIR}..." >&2
- if ! tar -xzf "${MVN_TAR}" -C "${MVN_DOWNLOAD_DIR}"; then
+ if ! (cd "${MVN_DOWNLOAD_DIR}" && tar -xzf "${MVN_TAR##*/}"); then
echo "ERROR: Failed to extract Maven" >&2
- rm -f "${MVN_TAR}"
+ rm -f "$MVN_TAR" "$MVN_SHA512"
exit 1
fi
- # Clean up tar file
- rm -f "${MVN_TAR}"
+ rm -f "$MVN_TAR" "$MVN_SHA512"
Review Comment:
The new `rm` and `tar` invocations should defensively use `--` before path
arguments to prevent option injection if any computed path ever begins with `-`
(e.g., from an overridden directory variable). For example: `rm -f -- ...` and
`tar -xzf -- ...`. This aligns with the PR goal of avoiding path interpretation
as options.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]