Skip to content

fix(transport): avoid filesize() on URLs when downloading packages - #75

Open
Ibochkarev wants to merge 4 commits into
3.xfrom
fix/16068-package-download-url-filesize
Open

fix(transport): avoid filesize() on URLs when downloading packages#75
Ibochkarev wants to merge 4 commits into
3.xfrom
fix/16068-package-download-url-filesize

Conversation

@Ibochkarev

@Ibochkarev Ibochkarev commented Aug 21, 2026

Copy link
Copy Markdown
Member

Что сделано

Загрузка пакета через allow_url_fopen больше не вызывает filesize() на remote URL (это вызывало PHP-предупреждения). Он читает уже открытый поток через stream_get_contents(), поэтому короткий fread() / неверный Content-Length не обрезает zip.

Хелперы остаются для тестов: getStreamOrFileSize() (последний числовой Content-Length после редиректов) и getReadByteLimit(). _bytes() использует ini_parse_quantity() на PHP 8.2+ и безопасный фолбэк на 8.1.

Зачем нужно

Загрузка экстра логировала filesize(): stat failed for https://… и связанные предупреждения (modxcms#16068).

Как проверить

  1. allow_url_fopen вкл, без прокси: установите пакет от провайдера; без filesize-предупреждений; zip устанавливается.
  2. phpunit --filter modTransportPackageTest

Связанные

Refs modxcms#16068

Оригинал: modxcms#16851

Use stream metadata Content-Length for URLs instead of filesize() which
fails on remote streams. For local paths, keep using filesize().

Refs modxcms#16068
Added comprehensive tests for the modTransportPackage class, including checks for local file sizes, URL handling with Content-Length headers, and scenarios with empty wrapper data. Introduced a custom stream wrapper for testing purposes to simulate various conditions.
Avoid filesize()/single fread on remote package URLs, prefer the final
Content-Length after redirects, and keep _bytes working on PHP 8.1 (modxcms#16068).
@Ibochkarev Ibochkarev changed the title fix(transport): не вызывать filesize() на URL при загрузке пакетов fix(transport): avoid filesize() on URLs when downloading packages Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant