Fixed Pruning proxied images does not reset file hash

Kirby

Well-known member
Affected version
2.2.8
When proxied images are being pruned after exipiry by calling \XF\Entity\ImageCache::prune(), their file_hash does not get reset.

Due to the change in https://xenforo.com/community/threads/image-proxy-refresh-seems-inefficient.198729/ this does cause successfully refetched images to not be written to disk again causing the images to show as broken forever.

So either
  1. file_hash must be reset
  2. The existence of the file must be checked before skipping the write
  3. Property pruned must be checked as well before skipping the write
Checking existence of the file would be the safest option, but also the most costly one; resetting the hash and checking pruned might be sufficient.
 
Last edited:
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.9).

Change log:
Reset file hash when pruning proxied images
There may be a delay before changes are rolled out to the XenForo Community.
 
No Guarantees

In src/XF/Service/ImageProxy.php

Replace
PHP:
if ($image->file_hash === $fileHash)
with
PHP:
if ($image->file_hash === $fileHash && !$image->pruned)
 
Last edited:
The pruned status will have been reset by virtue of the matching hash, so you will need to update the database to cause a refresh.

I've attached a patch you can apply.

After applying the patch, you can run:
SQL:
SELECT completion_date
FROM xf_upgrade_log
WHERE version_id = 2020870

This will give you the timestamp of when you upgraded to v2.2.8. You can then use run the following query to reset potentially affected images, replacing {completion_date} with the timestamp from the previous query:

SQL:
UPDATE xf_image_proxy
SET pruned = 1, file_hash = ''
WHERE fetch_date >= {completion_date}
 

Attachments

Last edited:
The pruned status will have been reset by virtue of the matching hash, so you will need to update the database to cause a refresh.

I've attached a patch you can apply.

After applying the patch, you can run:
SQL:
SELECT completion_date
FROM xf_upgrade_log
WHERE version_id = 2020870

This will give you the timestamp of when you upgraded to v2.2.8. You can then use run the following query to reset potentially affected images, replacing {completion_date} with the timestamp from the previous query:

SQL:
UPDATE xf_image_proxy
SET pruned = 1, file_hash = ''
WHERE fetch_date >= {completion_date}

Will this work even if I don't use a secret key?
 
Open src/XF/Entity/ImageProxy.php. Underneath line 234, add:
PHP:
        $this->file_hash = '';

The final result should look like this:
PHP:
        $this->pruned = true; 
        $this->file_hash = '';
        $this->save();
 
The pruned status will have been reset by virtue of the matching hash, so you will need to update the database to cause a refresh.

I've attached a patch you can apply.

After applying the patch, you can run:
SQL:
SELECT completion_date
FROM xf_upgrade_log
WHERE version_id = 2020870

This will give you the timestamp of when you upgraded to v2.2.8. You can then use run the following query to reset potentially affected images, replacing {completion_date} with the timestamp from the previous query:

SQL:
UPDATE xf_image_proxy
SET pruned = 1, file_hash = ''
WHERE fetch_date >= {completion_date}
I’m also not familiar with this.
Is there a different approach?
 
I have sent you a message, though generally the directions in my post above should be helpful to those who cannot apply the patch. You will still need to run the queries afterwards.
 
We've released XenForo 2.2.8 Patch 1 to address this issue:

 
We've released XenForo 2.2.8 Patch 1 to address this issue:

Do I need to be running PHP 8.1 to install the 2.2.8 patch ?
 
I'm running 2.2.8 patch 1, but am still experiencing this issue. I can't see the image in the post, but the image shows when I attempt to edit it.

Is there something else I should be doing?
 
Unlikely to be the same thing.

On balance, this is pretty normal. The image shows in the editor because we don't attempt to proxy it.

So the question is, why is the image not being displayed when proxied? You can answer that by using the test image proxy tool in the admin control panel.

After that if you need further support you should create a new troubleshooting thread.
 
Top Bottom