drewnoakes / metadata-extractor

Extracts Exif, IPTC, XMP, ICC and other metadata from image, video and audio files
Apache License 2.0
2.56k stars 480 forks source link

RafMetadataReader Unnecessary Buffer #385

Open payton opened 5 years ago

payton commented 5 years ago

RafMetadataReader.java takes in a 512 byte buffer and then continues to search that buffer for the JPEG file signature. Is there any justification for this?

We are able to get the JPEG image offset 84 bytes into the file (http://fileformats.archiveteam.org/wiki/Fujifilm_RAF) and avoid the large buffer.

https://github.com/drewnoakes/metadata-extractor/blob/5124606e5d3d1fa7183fb8435cf490448ef79279/Source/com/drew/imaging/raf/RafMetadataReader.java#L62-L82

kwhopper commented 5 years ago

This is well before my time but certainly seems like it could be done in fewer bytes.

However, as a test I'm tempted to modify this reader in the RandomAccessStream PR code to not create a local buffer at all. That branch would have read in the first 2K bytes anyway and then a sequential read in the for loop is all it would need to do...

RafMetadataReader.java

Mostly a plug for reviewing that PR. A single reader is one of the advantages I'm trying to promote.

payton commented 5 years ago

Agreed! I've been taking a look at it here and there. Given the size, it's tough to find time to look through it all.

drewnoakes commented 5 years ago

I'm not sure of the reasoning behind such a large buffer here.

I hope to find time soon to get a stable release out of both the Java and .NET libraries as they're long overdue a release. Then I'll look at @kwhopper's PRs.