Skip to content

Detect native PHAR archives #3

Description

@andrew

On v0.2.0 and current main, native PHAR archives return an empty Format from Detect. This prevents callers from distinguishing them from generic binary content without adding a PHAR parser of their own.

For example:

result := magic.Detect(nativePHAR)
fmt.Println(result.Format)
// ""

Add FormatPHAR for the native PHAR format. ZIP- and TAR-based PHARs should continue to return FormatZIP and FormatTAR, while gzip- or bzip2-wrapped native PHARs should continue to report their outer compression format.

Native PHAR detection needs more validation than a search for __HALT_COMPILER();. A PHP source file can contain that text without being an archive. Detection should locate the end of the stub, validate the following little-endian manifest, and check that entry headers and stored payload sizes fit within the input. Serialized PHP metadata can remain opaque bytes.

DetectPrefix should report ReasonNeedMore when the supplied prefix does not contain enough data to validate the manifest. PHP's default native stub is approximately 7 KB, so ordinary PHAR files will often extend beyond the current signature window and the global sniff limit can remain 512 bytes. This is needed by git-pkgs/archives#29 so .phar files can be routed by their physical container before archive parsing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions