Skip to content

feat(ext): add Zip support on libzip with php-src fixtures - #2193

Open
Guikingone wants to merge 1 commit into
illegalstudio:mainfrom
Guikingone:feat/zip-php-src-compliance
Open

Guikingone wants to merge 1 commit into
illegalstudio:mainfrom
Guikingone:feat/zip-php-src-compliance

Conversation

@Guikingone

@Guikingone Guikingone commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds PHP ext/zip support as a thin FFI layer over libzip 1.11.4, the same C library PHP itself uses. The managed native catalog provides libzip (with bzip2, XZ/LZMA, zlib, and OpenSSL), and elephc native add libzip installs the whole chain from verified sources. There is no system -lzip, -lbz2, -llzma, or -lcrypto fallback.

  • ZipArchive and the deprecated procedural zip_* API, built as AST declarations in src/zip_prelude/build.rs and verified structurally against tests/php_src/zip/prelude.php by the synthetic-class oracle.
  • zip:// and getStream*() user-space wrappers with PHP-shaped stream metadata, stream-context passwords, CRC-error reporting, read-mode enforcement, and archive-close invalidation.
  • Native packages: libzip 1.11.4, bzip2 1.0.8, xz 5.8.1. The resolver topologically orders managed archives so a program combining zip with curl/OpenSSL keeps every shared zlib/OpenSSL archive behind all of its dependents (GNU ld–safe).
  • Detection, --with-zip, linker bridge, autoload probe, CI/nightly/release packaging, docs (docs/php/zip.md), and examples/zip/ with its committed elephc.toml/elephc.lock.
  • The libzip recipe uses CMake; CI provisions a pinned, checksum-verified CMake (scripts/ci/ensure_cmake.sh) and passes its directory to every container step through ELEPHC_CI_EXTRA_PATH, so producer and consumer toolchain fingerprints agree. The Alpine test images include CMake.

The branch is one commit on current main (d430f58367), final head 87aec3320f, including the elephc-chopper parser move, the elephc build CLI, the uri bridge, and the recent checker/autoload/opcache changes.

Reviews and corrections

Three complete Ollama reviews (GLM 5.3-flash, MiniMax M3.1-flash, Mistral Large 4) drove the final correction passes. Valid findings fixed include:

  • Compiler-wide: restored the object-typed receiver fallthrough so method results are not silently coerced to Int (regression test added).
  • Link order: dependency-aware topological order for combined curl/zip/OpenSSL programs, with unit tests and a real curl+zip smoke job.
  • Archive semantics: duplicate addFile() now overwrites by default; extractTo() keeps php-src's positional selection semantics; getComment* returns "" for entries without comments; zip_entry_read() normalizes non-positive lengths; zip_entry_compressionmethod() follows php-src's method table; close() clears detached state and releases cancelled handles.
  • Streams: zip:// rejects write modes (r/rb/r+ accepted), reports CRC errors, matches wrapper schemes case-insensitively, and enforces open_basedir in open()/addFile()/replaceFile()/extractTo().
  • Targets: AT_FDCWD is per-OS, so extractTo() restores mtimes on macOS/iOS as well as Linux (covered by a test).
  • Robustness/hygiene: add_or_replace_file validates names before creating sources; elephc-zip tests are non-flaky; temporary fixture parents are removed; the prelude emits zero Unused variable warnings; stray scratch files were removed; release packaging builds libelephc_zip.a; OpenSSL recipe revisions were bumped for the iOS no-asm change; staticlib CMake identities are documented.
  • Expected behavior confirmed: PHP 8.5.10 itself returns partial bytes for CRC-corrupt getFromName() and extractTo() (only stream reads warn), extracts nothing for associative selection keys (only integer keys are read), throws for getExternalAttributesName(''), and omits wrapper_type for getStream* metadata; the bridge matches those results except that extractTo() now refuses the corrupt output.

A final Greptile pass found additional valid issues, corrected here:

  • Extraction safety: extractTo() refuses a final-component symlink (O_NOFOLLOW) and verifies the canonical parent stays inside the destination; archived permission bits are ignored, so a setuid/setgid entry cannot install a privileged file. The existing ../absolute-name sanitization remains.
  • Stream state: every getStream*() call gets its own position; stream_stat() reports the entry size; closing an archive clears its snapshots; close() invalidates streams on cancellation and callback-throw paths.
  • Wrapper metadata: stream_get_meta_data() copies the URI into owned storage and reports the actual fopen() mode, so saving metadata survives handle-slot reuse and writable wrappers no longer report "rb".
  • Pattern/glob errors: addPattern() accepts trailing modifiers (/...$/i) while still emitting PHP's "No ending delimiter" warning; addGlob()/addPattern() return failure when compression or encryption cannot be applied.
  • open_basedir: boundary-aware matching (root /, no component ..) is shared by open(), addFile(), replaceFile(), extractTo(), addGlob(), and addPattern().
  • Contracts/resources: the ten procedural zip_* functions have shared PreludeProvided contracts, ZipArchive and its internal helpers have class contracts, and zip_close()/zip_entry_close() release their temporary resources.
  • Semantics: setEncryptionName(..., null) uses the archive default password; removing an archive comment clears $zip->comment; a subclass getStream* override keeps its declared return type.
  • Exception cleanup: file_get_contents() closes its hidden wrapper descriptor when stream_read()/stream_eof() throws, so caught failures cannot exhaust the 256 handle slots.
  • Write-time callbacks: libzip now invokes the registered progress callback for intermediate progress and the cancel callback while close() writes, so deadline-based cancellation stops a large archive. The observable 0.0/1.0 progress endpoints remain PHP-side.
  • Corrupt extraction: extractTo() rejects a CRC-corrupt entry instead of installing its decoded bytes, a deliberate safety divergence from php-src 8.5.10.
  • CI provisioning: the pinned smoke, build-host, release, and nightly probes obtain the pinned CMake binary without apt-installing into pinned images; the smoke, build-host, and codegen consumers keep the same CMake PATH and an explicit ELEPHC_CMAKE path so native toolchain fingerprints match and libzip can find CMake. The iOS curl-link probe now reads the OpenSSL r2 artifacts instead of r1.

Verification

  • cargo build — clean apart from the pre-existing workspace manifest/build-script warnings.
  • cargo test --test codegen_tests_ext 'codegen::zip::' — 39 passed (including the new subclass, default-password, comment, corrupt-extraction, progress, cancel, and addGlob error cases).
  • cargo test --test codegen_tests_ext 'codegen::zip_php_src::' — 109 passed.
  • cargo test -p elephc-zip with ELEPHC_ZIP_NATIVE_LIB_DIRS — 11 passed (including symlink and privileged-mode extraction).
  • cargo test -p elephc --lib native_deps — 129 passed; zip — 10; prelude_probe — 12; the zip prelude AST oracle passes.
  • cargo test --test codegen_tests_oop test_object_typed_receiver_keeps_method_return_type — passes.
  • python3 -B -m unittest discover -s scripts/ci -p 'test_*.py' — 149 passed; test_variant_config needs Python ≥3.11 for tomllib, so the local Python 3.9 run reports only that import error.
  • codegen::io::streams::test_stream_get_meta_data_wrapper_keeps_uri_and_mode and test_file_get_contents_wrapper_read_throw_releases_handle — pass.
  • Builtin docs audits (audit_builtins, site compatibility, EIR boundary) pass; workflows and composite actions parse.
  • elephc build examples/zip/main.php && ./examples/zip/main — writes, reads, comments, extracts, and streams through real libzip; a zip build emits zero Unused variable warnings.
  • A macOS --with-curl --with-zip program links both chains and runs; CI's managed-native smoke exercises the same combination on Linux.
  • Full PR CI on the preceding 3995f5d118 — green: Linux and macOS codegen/non-codegen shards, managed-native smokes (libzip plus curl/zip link order), and builtins-docs sync.

php-src fixtures

The committed corpus is the PHP 8.5.10 ext/zip/tests suite (112 fixtures): 109 generated inline tests pass on macOS, oo_addfile_proc is Linux-only, bug51353 carries an unconditional php-src SKIPIF, and gh17319 expects false from PHP's own freed archive resource. Compiler-compatibility source rewrites are listed in tests/php_src/zip/README.md.

Supported targets

The bridge and native recipes cover macos-aarch64, ios-arm64, ios-sim-arm64, linux-aarch64, and linux-x86_64. The managed-native smoke builds libzip and its chain for both iOS targets; Linux executable coverage is supplied by the codegen shards and the curl+zip smoke.

Remaining documented differences

See docs/php/zip.md: user-space zip:// (eager entry read, fread()-prefixed CRC warning), getStream*() snapshot/seekable metadata, addPattern byte semantics/delimiters/x mode, addGlob option validation and GLOB_* coverage, non-UTF-8 and interior-NUL names, stricter .. extraction sanitization, custom extractTo stream wrappers, one-active-context model, the 72 KiB unconditional zip stream metadata tables, separate OpenSSL 3.5.8/3.6.4 static builds when zip and cipher are combined, intermediate progress-callback throws being swallowed by the bridge wrapper, and CMake not being part of the libzip artifact identity. extractTo() intentionally rejects CRC-corrupt payloads instead of installing them.

No CHANGELOG.md entry is included, per the repository's release-management policy.

@Guikingone
Guikingone marked this pull request as draft November 1, 2026 14:48
@github-actions github-actions Bot added area:runtime Touches runtime helpers, GC, ownership, or bridge runtimes. area:tooling-ci Touches CI, development tooling, Docker, or repository scripts. area:web Touches --web mode, its prelude, or elephc-web. scope:multi-area Touches more compiler areas than the automatic area-label cap. size:xl Very large pull request that needs deliberate review planning. type:feature Introduces new user-visible behavior or capabilities. labels Nov 1, 2026
@Guikingone Guikingone changed the title feat(zip): add PHP ext/zip support with php-src fixtures feat(exit): add PHP Zip support with php-src fixtures Nov 1, 2026
@Guikingone
Guikingone force-pushed the feat/zip-php-src-compliance branch from bc43213 to 8303241 Compare November 1, 2026 15:17
@Guikingone Guikingone added the ci:macos Run the macOS test matrix and iOS links on this PR, not only in the merge queue. label Nov 1, 2026
@Guikingone
Guikingone marked this pull request as ready for review November 1, 2026 15:17
@Guikingone
Guikingone marked this pull request as draft November 1, 2026 15:26
@Guikingone Guikingone changed the title feat(exit): add PHP Zip support with php-src fixtures feat(zip): add PHP ext/zip support on libzip with php-src fixtures Nov 1, 2026
@Guikingone
Guikingone marked this pull request as ready for review November 1, 2026 17:45
@Guikingone
Guikingone marked this pull request as draft November 1, 2026 17:45
@Guikingone
Guikingone marked this pull request as ready for review November 1, 2026 17:46
@Guikingone Guikingone closed this Nov 1, 2026
@Guikingone Guikingone reopened this Nov 1, 2026
@Guikingone
Guikingone marked this pull request as draft November 1, 2026 17:46
@Guikingone
Guikingone marked this pull request as ready for review November 1, 2026 17:46
@Guikingone
Guikingone marked this pull request as draft November 1, 2026 17:48
@Guikingone
Guikingone marked this pull request as ready for review November 1, 2026 17:48
@Guikingone
Guikingone force-pushed the feat/zip-php-src-compliance branch from 5b100c9 to 7fe7269 Compare November 1, 2026 17:48
@Guikingone
Guikingone marked this pull request as draft November 1, 2026 17:49
@Guikingone
Guikingone marked this pull request as ready for review November 1, 2026 17:50
@Guikingone
Guikingone force-pushed the feat/zip-php-src-compliance branch from 7fe7269 to 7173345 Compare November 1, 2026 17:50
@Guikingone
Guikingone marked this pull request as draft November 1, 2026 17:53
@Guikingone
Guikingone marked this pull request as ready for review November 1, 2026 17:54
@Guikingone
Guikingone force-pushed the feat/zip-php-src-compliance branch from 7173345 to 998ca9c Compare November 1, 2026 17:54
@Guikingone
Guikingone marked this pull request as draft November 1, 2026 17:57
Comment thread crates/elephc-zip/src/extract.rs Resolved
Comment thread src/zip_prelude/build.rs Outdated
Comment on lines +2215 to +2219
s_foreach(e_call("explode", vec![e_str(":"), e_var("allowed")]), None, "root", vec![
s_if(
e_binop(e_binop(e_var("root"), BinOp::StrictNotEq, e_str("")), BinOp::And, e_call("str_starts_with", vec![e_var("pattern"), e_var("root")])),
vec![
s_assign("inside", e_bool(true)),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 security Restricted paths escape their folder. The open_basedir check accepts any raw path starting with the allowed text. With /srv/data allowed, /srv/data-old/*.txt and /srv/data/../private/*.txt pass. The matches then reach addFile() without another folder check, so their contents enter the archive. Check each resolved file against resolved allowed directories, including a directory boundary. addPattern() needs the same check.

How this was verified: The prefix check feeds raw matches into addFile(), and the native read path has no further open_basedir check.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/zip_prelude/build.rs
Line: 2215-2219

Comment:
**Restricted paths escape their folder.** The `open_basedir` check accepts any raw path starting with the allowed text. With `/srv/data` allowed, `/srv/data-old/*.txt` and `/srv/data/../private/*.txt` pass. The matches then reach `addFile()` without another folder check, so their contents enter the archive. Check each resolved file against resolved allowed directories, including a directory boundary. `addPattern()` needs the same check.

**How this was verified:** The prefix check feeds raw matches into `addFile()`, and the native read path has no further `open_basedir` check.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex Fix in Cursor

Comment thread crates/elephc-zip/src/archive.rs Resolved
Comment on lines +73 to +79
emitter.instruction("ldr x10, [sp, #72]"); // reload the handle slot
abi::emit_symbol_address(emitter, "x3", "_zip_stream_uri"); // URI buffer base
emitter.instruction("add x3, x3, x10, lsl #8"); // slot * 256
abi::emit_symbol_address(emitter, "x9", "_zip_stream_uri_len"); // URI length table
emitter.instruction("ldr x4, [x9, x10, lsl #3]"); // stored URI length
emitter.instruction("mov x5, #1"); // value tag = string
emit_hash_put_aarch64(emitter, "_meta_key_uri", 3);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Saved stream URLs change. The returned metadata stores uri as a pointer into the reusable _zip_stream_uri buffer. __rt_hash_set copies the key, not the string value. Saving the metadata, closing the stream, and opening another wrapper in the same slot changes the old metadata's URL while keeping its old length. Copy the URL into owned string storage before putting it in the returned array.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/codegen_support/runtime/io/stream_get_meta_data.rs
Line: 73-79

Comment:
**Saved stream URLs change.** The returned metadata stores `uri` as a pointer into the reusable `_zip_stream_uri` buffer. `__rt_hash_set` copies the key, not the string value. Saving the metadata, closing the stream, and opening another wrapper in the same slot changes the old metadata's URL while keeping its old length. Copy the URL into owned string storage before putting it in the returned array.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex Fix in Cursor

Comment thread src/zip_prelude/detect.rs Resolved
Comment thread src/zip_prelude/build.rs
Comment on lines +2982 to +2984
s_assign("archive", e_index(e_index(e_static_prop("__ElephcZipProcedural", "state"), e_var("id")), e_int(0))),
s_static_prop_array_assign("__ElephcZipProcedural", "state", e_var("id"), e_null()),
s_expr(e_method_call(e_var("archive"), "close", vec![])),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Closed ZIP handles stay open. zip_open() and zip_read() allocate real temporary-file resources, but zip_close() and zip_entry_close() only clear their saved state. Neither closes the returned resource. Keeping references to already-closed handles therefore keeps their OS files open until those values are dropped. Close the backing resources when the procedural close functions run.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/zip_prelude/build.rs
Line: 2982-2984

Comment:
**Closed ZIP handles stay open.** `zip_open()` and `zip_read()` allocate real temporary-file resources, but `zip_close()` and `zip_entry_close()` only clear their saved state. Neither closes the returned resource. Keeping references to already-closed handles therefore keeps their OS files open until those values are dropped. Close the backing resources when the procedural close functions run.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex Fix in Cursor

Comment thread docs/php/zip.md Outdated
Comment on lines +122 to +129
- `addPattern()` accepts the PCRE subset the crate's `regex` engine understands and
matches names byte-wise like PCRE without the `u` modifier (the `u` modifier enables
Unicode matching). `i`, `m`, `s`, `x`, `u` and `A` are honored; `U` (ungreedy) has no
Rust-regex equivalent and is rejected rather than silently matched greedily. Lookarounds
and backreferences that only PCRE2 can evaluate are also rejected with
`ZipArchive::addPattern(): Invalid expression`.
- `addGlob()` honors `GLOB_BRACE`; the remaining `GLOB_*` ordering/only-directory
flags are not represented by the compiler's `glob()`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Required documentation is missing. AGENTS.md requires known PHP differences in docs/php/types.md and compiler-internal changes in docs/internals/. This PR adds ZIP differences and shared stream-runtime changes but updates neither location. Add the ZIP compatibility entry and document the new stream metadata storage and wrapper read path in the relevant internal guide.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: docs/php/zip.md
Line: 122-129

Comment:
**Required documentation is missing.** `AGENTS.md` requires known PHP differences in `docs/php/types.md` and compiler-internal changes in `docs/internals/`. This PR adds ZIP differences and shared stream-runtime changes but updates neither location. Add the ZIP compatibility entry and document the new stream metadata storage and wrapper read path in the relevant internal guide.

**Context Used:** AGENTS.md ([source](https://github.com/illegalstudio/elephc/blob/main/AGENTS.md))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Codex Fix in Cursor

@Guikingone
Guikingone force-pushed the feat/zip-php-src-compliance branch from 0ef4f3b to 0a6b96c Compare November 23, 2026 17:08
Comment on lines +53 to +58
emitter.instruction("bl __rt_stream_get_contents"); // x1/x2 = accumulated wrapper payload
emitter.instruction("stp x1, x2, [sp, #24]"); // preserve the result across close
emitter.instruction("bl __rt_str_persist"); // adopt scratch bytes into an owned result
emitter.instruction("stp x1, x2, [sp, #24]"); // persist any moved pointer/length
emitter.instruction("ldr x0, [sp, #16]"); // reload the synthetic fd
emitter.instruction("bl __rt_user_wrapper_fclose"); // run stream_close and release the handle slot

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Failed reads leave streams open. If stream_read() or stream_eof() throws, file_get_contents() skips its only call to __rt_user_wrapper_fclose. The hidden stream stays in _user_wrapper_handles. Repeated caught failures can fill all 256 slots and prevent later wrapper streams from opening. Add cleanup for escaping exceptions on both targets.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/codegen_support/runtime/io/file_get_contents_wrapper.rs
Line: 53-58

Comment:
**Failed reads leave streams open.** If `stream_read()` or `stream_eof()` throws, `file_get_contents()` skips its only call to `__rt_user_wrapper_fclose`. The hidden stream stays in `_user_wrapper_handles`. Repeated caught failures can fill all 256 slots and prevent later wrapper streams from opening. Add cleanup for escaping exceptions on both targets.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex Fix in Cursor

Comment thread src/zip_prelude/build.rs Outdated
Comment on lines +782 to +789
s_if(
e_binop(e_call("elephc_zip_result_ok", vec![]), BinOp::StrictEq, e_int(1)),
vec![
s_prop_assign(e_this(), "__elephc_comment", e_call("hex2bin", vec![e_var("comment")])),
],
vec![],
None,
),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Removed comments stay visible. Clearing an archive comment leaves $zip->comment showing the old text. __elephc_refresh() updates the saved property only when elephc_zip_result_ok() is true, but removing the comment makes archive_comment() return None. Reset the saved property to an empty string when there is no comment.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/zip_prelude/build.rs
Line: 782-789

Comment:
**Removed comments stay visible.** Clearing an archive comment leaves `$zip->comment` showing the old text. `__elephc_refresh()` updates the saved property only when `elephc_zip_result_ok()` is true, but removing the comment makes `archive_comment()` return `None`. Reset the saved property to an empty string when there is no comment.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex Fix in Cursor

Comment thread src/builtins/parity_tests.rs Outdated
Comment on lines +252 to +258
(
"zip_open",
"a deprecated procedural alias implemented by the zip prelude over ZipArchive. It has \
no `builtin!` binding and no `eval_builtin!` home; the prelude is the whole \
implementation. The comparison table therefore counts the zip module from the \
registry (0/10), while ZipArchive and the procedural API remain prelude-provided.",
),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 ZIP contracts go unchecked. The new zip_* entries join UNCONTRACTED_PRELUDE_DECLARATIONS instead of receiving shared contracts. CONTRIBUTING.md requires functions supplied by a prelude to have BuiltinKind::PreludeProvided contracts, even without a builtin! or eval_builtin! binding. Add the contracts for all ten functions before merging so their signatures receive the required checks.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/builtins/parity_tests.rs
Line: 252-258

Comment:
**ZIP contracts go unchecked.** The new `zip_*` entries join `UNCONTRACTED_PRELUDE_DECLARATIONS` instead of receiving shared contracts. `CONTRIBUTING.md` requires functions supplied by a prelude to have `BuiltinKind::PreludeProvided` contracts, even without a `builtin!` or `eval_builtin!` binding. Add the contracts for all ten functions before merging so their signatures receive the required checks.

**Context Used:** AGENTS.md ([source](https://github.com/illegalstudio/elephc/blob/main/AGENTS.md))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex Fix in Cursor

Comment thread .github/workflows/ci-build-host.yml Outdated
Comment on lines +720 to +722
if ! command -v cmake >/dev/null 2>&1; then
if command -v elephc-ci-apt-install >/dev/null 2>&1; then
elephc-ci-apt-install --no-install-recommends cmake

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Pinned jobs install missing packages. This producer installs cmake inside the pinned CI image when it is missing. CONTRIBUTING.md requires a missing dependency in a pinned test environment to fail rather than trigger package installation. Publish and select an image containing cmake, then remove this runtime install before merging. The ARM64 producer has the same pattern.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: .github/workflows/ci-build-host.yml
Line: 720-722

Comment:
**Pinned jobs install missing packages.** This producer installs `cmake` inside the pinned CI image when it is missing. `CONTRIBUTING.md` requires a missing dependency in a pinned test environment to fail rather than trigger package installation. Publish and select an image containing `cmake`, then remove this runtime install before merging. The ARM64 producer has the same pattern.

**Context Used:** AGENTS.md ([source](https://github.com/illegalstudio/elephc/blob/main/AGENTS.md))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex Fix in Cursor

@Guikingone
Guikingone force-pushed the feat/zip-php-src-compliance branch 5 times, most recently from 271b4a5 to 9e04fc0 Compare November 23, 2026 17:49
Comment thread src/zip_prelude/build.rs Outdated
s_if(
e_call("isset", vec![e_index(e_var("options"), e_str("enc_method"))]),
vec![
s_expr(e_method_call(e_this(), "setEncryptionName", vec![e_var("entry"), e_cast(CastType::Int, e_index(e_var("options"), e_str("enc_method"))), e_ternary(e_call("isset", vec![e_index(e_var("options"), e_str("enc_password"))]), e_cast(CastType::String, e_index(e_var("options"), e_str("enc_password"))), e_null())])),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 security Encryption failures look successful

__elephc_add_matches() ignores failed encryption and compression calls, then returns the file in its success list. An enc_password containing a NUL byte is rejected by CString::new() before encryption is set, but addGlob() still reports success and leaves the added entry unencrypted. Check both return values and return failure before adding the file to the success list.

How this was verified: The password rejection happens before zip_file_set_encryption(), while the caller drops the failed result and keeps the added entry.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/zip_prelude/build.rs
Line: 2187

Comment:
**Encryption failures look successful**

`__elephc_add_matches()` ignores failed encryption and compression calls, then returns the file in its success list. An `enc_password` containing a NUL byte is rejected by `CString::new()` before encryption is set, but `addGlob()` still reports success and leaves the added entry unencrypted. Check both return values and return failure before adding the file to the success list.

**How this was verified:** The password rejection happens before `zip_file_set_encryption()`, while the caller drops the failed result and keeps the added entry.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex Fix in Cursor

Comment on lines +89 to +91
if let Some(stream_type) = self.zip_stream_method_return(class_name, method) {
self.infer_method_call_on_class_type(class_name, method, args, expr, env)?;
return Ok(stream_type);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 ZIP overrides get wrong types

zip_stream_method_return() forces resource|false onto user overrides too. A subclass may legally declare getStream(string $name): string, because the parent method has no declared return type. Calls to that override still lose their actual string type here. This can reject valid typed uses or send the wrong value shape downstream. Apply this special case only when the selected method is the inherited ZIP implementation.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/types/checker/inference/objects/methods.rs
Line: 89-91

Comment:
**ZIP overrides get wrong types**

`zip_stream_method_return()` forces `resource|false` onto user overrides too. A subclass may legally declare `getStream(string $name): string`, because the parent method has no declared return type. Calls to that override still lose their actual string type here. This can reject valid typed uses or send the wrong value shape downstream. Apply this special case only when the selected method is the inherited ZIP implementation.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex Fix in Cursor

Comment thread src/zip_prelude/build.rs

/// `ZipArchive` — transcribed from the PHP form.
fn decl_class_ziparchive() -> Stmt {
class("ZipArchive")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 ZIP classes lack shared contracts

The new ZipArchive declaration has no entry in catalog_classes.rs. CONTRIBUTING.md requires every supplied class to have a shared class contract, including classes declared by a prelude. Add ZipArchive and the new internal helper classes to that catalog before merging so their module and visibility information stays shared.

Context Used: AGENTS.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/zip_prelude/build.rs
Line: 622

Comment:
**ZIP classes lack shared contracts**

The new `ZipArchive` declaration has no entry in `catalog_classes.rs`. `CONTRIBUTING.md` requires every supplied class to have a shared class contract, including classes declared by a prelude. Add `ZipArchive` and the new internal helper classes to that catalog before merging so their module and visibility information stays shared.

**Context Used:** AGENTS.md ([source](https://github.com/illegalstudio/elephc/blob/main/AGENTS.md))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Codex Fix in Cursor

@Guikingone
Guikingone force-pushed the feat/zip-php-src-compliance branch from 9e04fc0 to 7f7a9fd Compare November 23, 2026 19:00
emitter.label("__rt_sgmd_synth_generic");
emit_set_str_const(emitter, "_meta_key_stream_type", 11, "_meta_stype_userspace", 10);
emit_set_str_const(emitter, "_meta_key_wrapper_type", 12, "_meta_wrapper_userspace", 10);
emit_set_str_const(emitter, "_meta_key_mode", 4, "_meta_mode_rb", 2);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Writable streams look read-only

The new generic wrapper branch always reports mode="rb", even when fopen() opened the wrapper with "w", "a", or "r+". The requested mode reaches stream_open() but is not saved for metadata, so callers checking the mode get the wrong answer. Save and return the actual mode on both AArch64 and x86_64.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/codegen_support/runtime/io/stream_get_meta_data.rs
Line: 85

Comment:
**Writable streams look read-only**

The new generic wrapper branch always reports `mode="rb"`, even when `fopen()` opened the wrapper with `"w"`, `"a"`, or `"r+"`. The requested mode reaches `stream_open()` but is not saved for metadata, so callers checking the mode get the wrong answer. Save and return the actual mode on both AArch64 and x86_64.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex Fix in Cursor

Comment thread crates/elephc-zip/src/tests.rs Outdated
// password may pass the header check on one build and fail on another. Either the read
// errors or it must not return the original plaintext.
if let Ok(data) = reopened.payload(0, 0) {
assert_ne!(data, b"legacy payload");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Wrong-password test checks unrelated bytes

aes_encryption_requires_the_password() encrypts b"classified", but its wrong-password check compares returned bytes with b"legacy payload". If a wrong password returns the original plaintext, this test still passes. Compare with b"classified" so the assertion catches that failure.

Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/elephc-zip/src/tests.rs
Line: 111

Comment:
**Wrong-password test checks unrelated bytes**

`aes_encryption_requires_the_password()` encrypts `b"classified"`, but its wrong-password check compares returned bytes with `b"legacy payload"`. If a wrong password returns the original plaintext, this test still passes. Compare with `b"classified"` so the assertion catches that failure.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex Fix in Cursor

@Guikingone
Guikingone force-pushed the feat/zip-php-src-compliance branch from 7f7a9fd to bb5e325 Compare November 23, 2026 20:01
Comment thread scripts/ci/ensure_cmake.sh Resolved
@Guikingone
Guikingone force-pushed the feat/zip-php-src-compliance branch from bb5e325 to ba16736 Compare November 23, 2026 20:20
Comment thread crates/elephc-zip/src/extract.rs Outdated
Comment on lines +50 to +51
let data = archive.payload(index, 0)?;
fs::write(&target, data).map_err(|_| ZipError::Write)?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Corrupt extractions report success

When an entry fails its CRC check, extractTo() still writes the returned bytes and reports success. It calls payload(), which drops the error flag from payload_stream(). A damaged archive can therefore leave a truncated or corrupt file without any failure signal. Use the CRC-preserving read here and return an error when the check fails.

Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/elephc-zip/src/extract.rs
Line: 50-51

Comment:
**Corrupt extractions report success**

When an entry fails its CRC check, `extractTo()` still writes the returned bytes and reports success. It calls `payload()`, which drops the error flag from `payload_stream()`. A damaged archive can therefore leave a truncated or corrupt file without any failure signal. Use the CRC-preserving read here and return an error when the check fails.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex Fix in Cursor

@Guikingone
Guikingone force-pushed the feat/zip-php-src-compliance branch from ba16736 to a326b96 Compare November 23, 2026 21:23
("elephc_openssl", &["openssl-crypto"]),
// The archive bridge is a thin FFI layer over libzip; the catalog splices in
// its bzip2/xz/zlib/OpenSSL dependency chain.
("elephc_zip", &["libzip"]),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 ZIP blocks publication

Adding libzip here makes the release and nightly probes build it too. Those jobs still select the unchanged smoke22 image and do not prepare CMake. If that pinned image lacks CMake, a cold Linux probe fails with “cmake is required” and blocks publication. Adding CMake to the Dockerfile only affects future image builds. Publish and pin the updated image before adding this requirement.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/linker/native_packages.rs
Line: 40

Comment:
**ZIP blocks publication**

Adding `libzip` here makes the release and nightly probes build it too. Those jobs still select the unchanged `smoke22` image and do not prepare CMake. If that pinned image lacks CMake, a cold Linux probe fails with “cmake is required” and blocks publication. Adding CMake to the Dockerfile only affects future image builds. Publish and pin the updated image before adding this requirement.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex Fix in Cursor

@Guikingone
Guikingone force-pushed the feat/zip-php-src-compliance branch 11 times, most recently from c48a1ea to 3995f5d Compare November 26, 2026 15:02
Replace the pure-Rust archive engine with an FFI bridge over libzip
1.11.4 and the catalog's bzip2, XZ, zlib and OpenSSL packages. Migrate
the PHP 8.5.10 ext/zip corpus, add the ZipArchive/zip_* prelude and the
zip:// stream wrapper, expose --with-zip, and wire the bridge through
the native package table, codegen harness, CI workflows and docs.
@Guikingone
Guikingone force-pushed the feat/zip-php-src-compliance branch from 3995f5d to 87aec33 Compare November 26, 2026 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:runtime Touches runtime helpers, GC, ownership, or bridge runtimes. area:tooling-ci Touches CI, development tooling, Docker, or repository scripts. area:web Touches --web mode, its prelude, or elephc-web. ci:macos Run the macOS test matrix and iOS links on this PR, not only in the merge queue. scope:multi-area Touches more compiler areas than the automatic area-label cap. size:xl Very large pull request that needs deliberate review planning. type:feature Introduces new user-visible behavior or capabilities.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant