[guardian-dev] sanitizing PNGs

Michael Rogers michael at briarproject.org
Wed Dec 13 09:05:06 EST 2017


Please feel free to use it, I place it in the public domain. I'll have a
look at JPEGs next time I'm procrastinating. ;-)

(By the way, after sending I noticed a bug: if the file ends with a
truncated ancillary chunk, I think the cleaner will loop forever trying
to skip to the end of the chunk. Should be easy to fix though.)

Cheers,
Michael

On 13/12/17 13:02, Hans-Christoph Steiner wrote:
> 
> That's awesome!  Feeling inspired to also strip JPEGs? :-)  I think
> they're easier.  There is jhead, exiftool, and ObscuraCam's JNI code for
> examples.  Can we use this under the GPLv3?
> 
> .hc
> 
> Michael Rogers:
>> Hi Hans-Christoph,
>>
>> I hacked this together based on the PNG specification, which
>> distinguishes between ancillary chunks that can be removed without
>> affecting the image data, and critical chunks that can't. It's been
>> tested on exactly two PNGs so far. :-)
>>
>> http://www.libpng.org/pub/png/spec/1.2/PNG-Structure.html
>>
>> Cheers,
>> Michael
>>
>> On 12/12/17 16:25, Hans-Christoph Steiner wrote:
>>>
>>> pyexiftool is just a wrapper for exiftool.  exiftool looks great, but
>>> for my use case, I only need to strip all metadata.  It would be much
>>> easier if that was in pure Python and pure Java.  perl is a no go on
>>> Android.
>>>
>>> It was dead simple to strip EXIF from JPEG in Python:
>>>
>>>         from pil import Image
>>>         with open(inpath) as fp:
>>>             in_image = Image.open(fp)
>>>             data = list(in_image.getdata())
>>>             out_image = Image.new(in_image.mode, in_image.size)
>>>         out_image.putdata(data)
>>>         out_image.save(outpath)
>>>
>>> But that broke some PNGs, and the rest were larger in size.
>>>
>>> .hc
>>>
>>> Rick Valenzuela:
>>>> oh, you may already know this, but the previous code keeps a copy of the
>>>> file and metadata. if you want it gone with no copies, you have to add a
>>>> switch to overwrite, e.g.:
>>>>
>>>> ```
>>>> with exiftool.ExifTool() as et:
>>>>     et.execute(b'-all=', b'-overwrite_original', b'some.png')
>>>> ```
>>>>
>>>> On 12/12/2017 23:45, Rick Valenzuela wrote:
>>>>> heh, nice --  I just found this:
>>>>>
>>>>> https://github.com/smarnach/pyexiftool
>>>>>
>>>>> Tried it out and it worked great:
>>>>> ```
>>>>> with exiftool.ExifTool() as et:
>>>>>      et.execute(b'-all=', b'some.png')
>>>>> ```
>>>>>
>>>>> On 12/12/2017 19:53, Hans-Christoph Steiner wrote:
>>>>>>
>>>>>> Ah, cool, I thought exiftool only worked with JPEGs.  It seems to work
>>>>>> with just about every image format.  Now the open question is how to
>>>>>> strip all PNG metadata with Python and Java.
>>>>>>
>>>>>> .hc
>>>>>>
>>>>>> Rick Valenzuela:
>>>>>>> does exiftool do what you need?
>>>>>>>
>>>>>>> `exiftool -all= <some.PNG>`
>>>>>>>
>>>>>>> On 11/12/2017 17:57, Hans-Christoph Steiner wrote:
>>>>>>>>
>>>>>>>> Anyone know any tools for sanitizing PNGs without touching the
>>>>>>>> compressed image data?  With JPEG it is easy to strip out EXIF with
>>>>>>>> python-pil or many other tools. I haven't found a simple, clean approach
>>>>>>>> in Python for PNGs.
>>>>>>>>
>>>>>>>> .hc
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0x9FC527CC.asc
Type: application/pgp-keys
Size: 4660 bytes
Desc: not available
URL: <http://lists.mayfirst.org/pipermail/guardian-dev/attachments/20171213/6d2a6c03/attachment-0001.key>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
URL: <http://lists.mayfirst.org/pipermail/guardian-dev/attachments/20171213/6d2a6c03/attachment-0001.sig>


More information about the guardian-dev mailing list