From d4ce56b9018589e5157efca7f07e23c5e44ffe29 Mon Sep 17 00:00:00 2001 From: postie Date: Thu, 12 Mar 2026 21:32:29 +0000 Subject: Only download up to 256KiB of HTML for LinkPreview --- Digitigrade/LinkPreview.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Digitigrade/LinkPreview.php') diff --git a/Digitigrade/LinkPreview.php b/Digitigrade/LinkPreview.php index 706c3c7..718a196 100644 --- a/Digitigrade/LinkPreview.php +++ b/Digitigrade/LinkPreview.php @@ -32,7 +32,8 @@ class LinkPreview implements \JsonSerializable { // TODO: Respect Content-Type header from response, maybe set an Accept header in the request? // I was able to find a URL serving SHIFT-JIS, but they do not specify a charset in the Content-Type header. // https://www2d.biglobe.ne.jp/~msyk/charcode/cp932/Windows-31J-charset.html - $c = @file_get_contents($this->url); + $max_length = 256 * 1024; // 256KiB should be enough for the document head + $c = @file_get_contents($this->url, false, null, 0, $max_length); if (!$c) return false; $d = \Dom\HTMLDocument::createFromString($c, LIBXML_NOERROR); -- cgit v1.3