Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jPSlJ-0003il-3X for pgsql-general@arkaria.postgresql.org; Fri, 17 Apr 2020 15:18:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jPSlI-0002wS-0P for pgsql-general@arkaria.postgresql.org; Fri, 17 Apr 2020 15:18:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jPSlH-0002sn-NT for pgsql-general@lists.postgresql.org; Fri, 17 Apr 2020 15:18:35 +0000 Received: from hermes.gatewaynet.com ([193.92.121.98]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jPSlE-000354-TT for pgsql-general@lists.postgresql.org; Fri, 17 Apr 2020 15:18:35 +0000 Received: from hercules.internal.net (hercules.internal.net [10.9.200.8]) by hermes.gatewaynet.com (8.15.2/8.15.2/Debian-8) with ESMTP id 03HFIUXt027070 for ; Fri, 17 Apr 2020 18:18:30 +0300 Received: from [10.9.251.249] (dcmchgw.internal.net [10.9.0.1]) by hercules.internal.net (Postfix) with ESMTPS id 92E451350B69 for ; Fri, 17 Apr 2020 18:18:29 +0300 (EEST) Subject: Re: easy way to acquire height / width from images (PNG, JPEG) stored as bytea? To: pgsql-general@lists.postgresql.org References: <03a79221-6e00-4d8e-c6bc-c01cadb352d9@matrix.gatewaynet.com> <96fadd6d-d7f9-4365-d008-6ba25233c867@matrix.gatewaynet.com> From: Achilleas Mantzios Message-ID: Date: Fri, 17 Apr 2020 18:18:28 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------95EC448AEE7011647007E646" Content-Language: en-US X-Virus-Scanned: clamav-milter 0.101.4 at hermes X-Virus-Status: Clean X-Spam-Status: No, score=-21.9 required=5.0 tests=ALL_TRUSTED,DYN_HAM_IT, DYN_HAM_IT_PARTNERS,DYN_HAM_SIGNAT1,DYN_SPAM_SUBJ,HTML_MESSAGE,TW_BP, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on hermes.gatewaynet.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------95EC448AEE7011647007E646 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 17/4/20 6:14 μ.μ., Imre Samu wrote: > > it killed my 200+ days uptime FreeBSD box :( . > > As I describe above, those attachments are nowhere as files. > > They are email attachments. Also we got about half TB of them. > > it is possible - that  some image is a "decompression bomb" ? > > /"Because of the efficient compression method used in Portable Network > Graphics (PNG) files, a small PNG file can expand tremendously, acting > as a "decompression bomb". *Malformed PNG chunks can consume a large > amount of CPU and wall-clock time and large amounts of memory, up to > all memory available on a system, causing a Denial of Service (DoS).* > Libpng-1.4.1 has been revised to use less CPU time and memory, and > provides functions that applications can use to further defend against > such files."/ > https://libpng.sourceforge.io/decompression_bombs.html > https://stackoverflow.com/questions/33602308/how-to-check-png-file-if-its-a-decompression-bomb > > Regards, >  Imre Thank you  a lot Imre. Great info. > > > Achilleas Mantzios > ezt írta (időpont: 2020. ápr. > 17., P, 16:39): > > On 17/4/20 4:09 μ.μ., Adam Brusselback wrote: > >> Why not extract and store that metadata with the image rather >> than trying to extract it to filter on at query time? That way >> you can index your height and width columns to speed up that >> filtering if necessary. >> > Yes I thought of that, but those are coming automatically from our > mail server (via synonym), we have written an alias : a program > that parses and stores emails. This is generic, I wouldn't like to > add specific code (or specific columns) just for image > attachments. However I dig the idea of the indexes. >> You may be able to write a wrapper for a command line tool like >> imagemagic or something so you can call that from a function to >> determine the size if you did want to stick with extracting that >> at query time. > As I describe above, those attachments are nowhere as files. They > are email attachments. Also we got about half TB of them. > --------------95EC448AEE7011647007E646 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit


On 17/4/20 6:14 μ.μ., Imre Samu wrote:
> it killed my 200+ days uptime FreeBSD box :( .
> As I describe above, those attachments are nowhere as files. 
> They are email attachments. Also we got about half TB of them.

it is possible - that  some image is a "decompression bomb" ?

"Because of the efficient compression method used in Portable Network Graphics (PNG) files, a small PNG file can expand tremendously, acting as a "decompression bomb". Malformed PNG chunks can consume a large amount of CPU and wall-clock time and large amounts of memory, up to all memory available on a system, causing a Denial of Service (DoS). Libpng-1.4.1 has been revised to use less CPU time and memory, and provides functions that applications can use to further defend against such files."

Regards,
 Imre


Thank you  a lot Imre. Great info.




Achilleas Mantzios <achill@matrix.gatewaynet.com> ezt írta (időpont: 2020. ápr. 17., P, 16:39):

On 17/4/20 4:09 μ.μ., Adam Brusselback wrote:

Why not extract and store that metadata with the image rather than trying to extract it to filter on at query time? That way you can index your height and width columns to speed up that filtering if necessary.

Yes I thought of that, but those are coming automatically from our mail server (via synonym), we have written an alias : a program that parses and stores emails. This is generic, I wouldn't like to add specific code (or specific columns)  just for image attachments. However I dig the idea of the indexes.
You may be able to write a wrapper for a command line tool like imagemagic or something so you can call that from a function to determine the size if you did want to stick with extracting that at query time.
As I describe above, those attachments are nowhere as files. They are email attachments. Also we got about half TB of them.
--------------95EC448AEE7011647007E646--