Skip to content

[2.1.18] Subs-Attachments.php: Line 698, bool treated as array, forum error generated after attaching .txt or .pdf #9787

Open

Description

@smith-48116

Basic Information

I am using Apache 2.4 (32-bit), PHP 8.5.10 (32-bit) and was seeing this error on every .txt or .pdf attachment.

I am not a PHP programmer so I relied on ChatGPT to identify and patch the problem.

Excuse me in advance if the etiquette for reports is supposed to exclude AI bug identification or patches.


ChatGPT:

The code treats a Boolean false as an array, and I confirmed the exact cause in your installed forum.
Both logs identify Subs-Attachments.php, line 698:

The failing code is:

$size = @getimagesize($attachmentOptions['tmp_name']);
list ($attachmentOptions['width'], $attachmentOptions['height']) = $size;

getimagesize() returns an array for supported images, but returns false when it cannot determine image dimensions. A PDF or other non-image attachment can therefore reach the next line with $size === false.

The appropriate replacement is:

$size = @getimagesize($attachmentOptions['tmp_name']);
list ($attachmentOptions['width'], $attachmentOptions['height']) =
$size !== false ? $size : array(0, 0);

This preserves image dimensions and uses zero dimensions for other attachments. The existing SVG handling immediately afterward remains applicable.

I reproduced the exact warning using your local PHP 8.5.10 executable. The guarded version completed without that warning. The logs alone don’t identify which uploaded files caused it; an unreadable or damaged image could also return false.


Attached is a patch from ChatGPT for the line in question. Search 'ChatGPT' to locate the patch.

Subs-Attachments.php

Steps to reproduce

  1. Create a new post, attach a .pdf, upload and finalize post.
  2. Error is generated in Admin log.

Expected result

No response

Actual result

No response

Version/Git revision

2.1.18

Database Engine

MySQL

Database Version

No response

PHP Version

8.5.10

Logs

Additional Information

Activity

  1. sbulen commented on Oct 21, 2026

    @sbulen
    Contributor

    Not seeing this on php 8.4. Will be able to test 8.5 later...

  2. smith-48116 commented on Oct 21, 2026

    @smith-48116
    Author

    Thanks for looking at it. I am sure you guys are already aware, but you might want to update to the latest version of PHP!

    https://www.nsa.gov/Press-Room/Press-Releases-Statements/Press-Release-View/Article/4630238/nsa-advisory-php-updates/

    I posted this report with my prior version, as submitted in the report, but I have upgraded to the latest version because of that advisory.

  3. sbulen commented on Oct 23, 2026

    @sbulen
    Contributor

    I have confirmed these both on php 8.5, but neither exist on php 8.4.

    Change in 8.5 on list() processing:

    8.5.0 Destructuring a non-array value (other than null) now emits an E_WARNING.

    So this is a new PHP 8.5 issue...

  4. added this to the 2.1.9 milestone on Oct 25, 2026
  5. linked a pull request that will close this issue[2.1] PHP 8.5 fixes #9798on Oct 25, 2026
  6. sbulen commented on Oct 25, 2026

    @sbulen
    Contributor

    Note this was reported in the forum as well:
    https://www.simplemachines.org/community/index.php?topic=594725.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions