diff --git a/product-source/hololake-platform/guanghu-os/pncc-runtime/pncc-runtime.mjs b/product-source/hololake-platform/guanghu-os/pncc-runtime/pncc-runtime.mjs index 688b7c5c0..fb95d423d 100644 --- a/product-source/hololake-platform/guanghu-os/pncc-runtime/pncc-runtime.mjs +++ b/product-source/hololake-platform/guanghu-os/pncc-runtime/pncc-runtime.mjs @@ -76,10 +76,13 @@ function exactGitRoot(repository) { function committedArtifact(repository, head, path) { validateRelativePath(path) - const object = validateFullHead(String(runGit(repository, ['rev-parse', `${head}:${path}`], 'PNCC_GIT_OBJECT_ID_READ')).trim().toLowerCase()) + const treeEntry = String(runGit(repository, ['ls-tree', head, '--', path], 'PNCC_GIT_TREE_ENTRY_READ')).trim() + const match = treeEntry.match(/^([0-9]{6}) blob ([0-9a-f]{40})\t(.+)$/u) + if (!match || match[3] !== path) fail('PNCC_COMMITTED_PATH_NOT_EXACT_BLOB', path) + const mode = match[1] + const object = validateFullHead(match[2].toLowerCase()) const type = String(runGit(repository, ['cat-file', '-t', object], 'PNCC_GIT_OBJECT_TYPE_READ')).trim() if (type !== 'blob') fail('PNCC_COMMITTED_OBJECT_NOT_BLOB', path) - const mode = String(runGit(repository, ['ls-tree', head, '--', path], 'PNCC_GIT_OBJECT_MODE_READ')).trim().split(/\s+/u)[0] if (!['100644', '100755'].includes(mode)) fail('PNCC_COMMITTED_OBJECT_NOT_REGULAR_FILE', path) const bytes = runGit(repository, ['cat-file', 'blob', object], 'PNCC_GIT_OBJECT_READ', { encoding: 'buffer' }) if (!Buffer.isBuffer(bytes) || bytes.length === 0 || bytes.length > MAX_ARTIFACT_BYTES) {