Repository navigation
Conversation
Thumbnail creation now reads the image's width and height from its header with an ImageReader before decoding it. Images with more pixels than the new uploads.thumbnail.maxPixels setting (default 50,000,000) are stored without a thumbnail, and the skip is logged. Other images are decoded with subsampling sized to the thumbnail. The upload's content stream is now closed, and content that no image reader recognizes gets no thumbnail whatever content type the client sent.
snoopdave
reviewed
Nov 18, 2026
snoopdave
left a comment
Contributor
There was a problem hiding this comment.
Review of 09480c48e: The header check and subsampled read are present. PR #327 has the same fix hunks; its diff differs only in branch context. The skip path needs changes for replaced files and for how oversized images appear in the UI.
The width and height read from an image's header are now saved before the pixel limit is checked, so an image too large for a thumbnail still shows its real size. When a file's new content gets no thumbnail, for any reason, the thumbnail left from its previous content is removed, so a replaced image no longer shows the old image's thumbnail. MediaResourceServlet answers 404 to a thumbnail request for an image over uploads.thumbnail.maxPixels instead of sending the full image, so the media library and chooser show the file type icon. Other images without a thumbnail are still served in full at the thumbnail address. The upload result page shows the file type icon for such images, and inserting one into an entry uses the image's own address.
# Conflicts: # app/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/MediaResourceServlet.java
A value of uploads.thumbnail.maxPixels that is not a positive int (for example 50_000_000, 3000000000, an empty value or 0) used to throw NumberFormatException out of the media servlet and the media library pages, and silently stopped thumbnails being made on upload. The limit is now read in one place, MediaFile.thumbnailMaxPixels(), which falls back to the default and logs a warning once for each bad value. When a file's content is replaced with something no image reader recognizes, or whose header can't be read, the stored width and height are reset to -1 (unknown), so the previous image's size no longer marks the new content as over the limit. The derived overThumbnailPixelLimit getter is listed as transient in MediaFile.orm.xml like the other derived getters.
snoopdave
reviewed
Nov 20, 2026
snoopdave
left a comment
Contributor
There was a problem hiding this comment.
Review of c945f86e0: The earlier review points are resolved, and the tests cover the upload skip and thumbnail response paths. One issue remains: thumbnail availability is inferred from the current pixel limit, which can differ from the limit used when the file was uploaded.
Earlier comments: 3 of 3 resolved.
Whether an image has a thumbnail was worked out from the current uploads.thumbnail.maxPixels setting, but the thumbnail was made or skipped at upload time, so changing the limit later could make a file with a thumbnail look like it had none, or the other way around. isOverThumbnailPixelLimit() is replaced by isThumbnailSkipped(), which is true for an image whose size was read on upload but which has no _sm file stored, whatever the limit is now.
The limit-change tests now end the session before reloading the file without its content, as the list views load it, so whether it has a thumbnail is looked up in the file store rather than read from the instance loaded during upload.
Most images on an upgraded blog have no _sm file, because they were carried over from older versions or by migrations, so treating every image without one as skipped would have taken away their previews. An image now counts as skipped only when it has no _sm file and its recorded size is over the current uploads.thumbnail.maxPixels; an image without a thumbnail under the limit is previewed from the original as before, and one with a thumbnail always gets it.
# Conflicts: # app/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/MediaResourceServlet.java
… to scale The subsampling step now comes from whichever side needs the larger step, so both sides are decoded at about twice the thumbnail size. An image so much wider than tall, or taller than wide, that its thumbnail would be less than a pixel across is no longer decoded, since no thumbnail could be made from it anyway. Setting a media file's width or height also resets its cached thumbnail size, so a replaced image's thumbnail gets the new image's shape.
These are the formats whose image readers decode a subsampled image row by row. The TIFF reader reads a whole strip or tile into memory even when subsampling, so TIFF images, and any other format a reader is installed for, are now stored with their size and without a thumbnail. The format comes from the content, not the file name.
Running out of memory while decoding an image for its thumbnail is logged and leaves the image without a thumbnail, instead of failing the upload after the file was saved. An image whose header can be read but whose pixels can't is stored without a size, as it was before the size came from the header. A thumbnail that was saved is kept when a later step fails, and removing an old thumbnail also clears it from the media file and logs failures other than a missing file.
Entries that embed an image's thumbnail address showed a broken image once the image was stored without a thumbnail, because the thumbnail request answered 404. The thumbnail request now falls back to the original, as it does for any image without a thumbnail. The media library and chooser cards show the file type icon for such an image themselves, so they don't load the original as a preview.
…wn name The invalid-limit test named its uploads by the length of the limit value, so two of them shared a name.
…hat isn't an image Before, the replaced image's thumbnail was still served at the file's thumbnail address.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thumbnail creation in
JPAMediaFileManagerImplnow reads an image's width and height from its header with anImageReaderbefore decoding it, and decodes only what the thumbnail needs.uploads.thumbnail.maxPixelssetting (default 50,000,000) are stored without a thumbnail, and the skip is logged. The upload still succeeds and keeps the image's real width and height.?t=trueaddress keep showing the image. For images over the limit, the media library and chooser cards, the upload result page and "create entry" checkthumbnailSkippedthemselves and show the file type icon or link the image directly.uploads.thumbnail.maxPixels(such as50_000_000, a value over the int range, empty or 0) logs a warning and uses the default.Tests:
MediaFileThumbnailTest(DB-backed) covers an image over a configured limit, a normal image, a PNG whose header claims 50000x50000, a very wide image, a TIFF image (also under a.pngname), an image that can't be decoded, and replacements by an over-limit image, unreadable content and a non-image.ThumbnailSubsamplingTestcovers the subsampling step and the thumbnail size after a size change.MediaResourceThumbnailTestcovers thumbnail requests.MediaFileTeststill passes.CHANGES lists the limit and the TIFF change under "Limits on uploads and fetched feeds".