summaryrefslogtreecommitdiff
path: root/src/photos/JfifSupport.vala
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2018-05-01 14:35:32 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2018-05-01 14:35:32 +0200
commite230b6f78546827521107be23797048482c8b193 (patch)
tree948c1e77382c484819ea399bba4edcdc19cc6bf0 /src/photos/JfifSupport.vala
parent211da5fc3048ca2b6ccee2166b0aaaade55cb84f (diff)
parent49120f48474fc8fdc2448c75d961bc238213cfac (diff)
Update upstream source from tag 'upstream/0.28.2'
Update to upstream version '0.28.2' with Debian dir 811236a8e9a1308bf427065dcb6270419ff4f965
Diffstat (limited to 'src/photos/JfifSupport.vala')
-rw-r--r--src/photos/JfifSupport.vala22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/photos/JfifSupport.vala b/src/photos/JfifSupport.vala
index 2861353..5ea64a5 100644
--- a/src/photos/JfifSupport.vala
+++ b/src/photos/JfifSupport.vala
@@ -201,16 +201,25 @@ namespace Jpeg {
}
public bool is_jpeg(File file) throws Error {
- FileInputStream fins = file.read(null);
-
+ var fins = file.read(null);
+ return is_jpeg_stream(fins);
+ }
+
+ public bool is_jpeg_stream(InputStream ins) throws Error {
Marker marker;
- int segment_length = read_marker(fins, out marker);
+ int segment_length = read_marker(ins, out marker);
// for now, merely checking for SOI
return (marker == Marker.SOI) && (segment_length == 0);
}
- private int read_marker(FileInputStream fins, out Jpeg.Marker marker) throws Error {
+ public bool is_jpeg_bytes(Bytes bytes) throws Error {
+ var mins = new MemoryInputStream.from_bytes(bytes);
+
+ return is_jpeg_stream(mins);
+ }
+
+ private int read_marker(InputStream fins, out Jpeg.Marker marker) throws Error {
marker = Jpeg.Marker.INVALID;
DataInputStream dins = new DataInputStream(fins);
@@ -226,8 +235,9 @@ namespace Jpeg {
}
uint16 length = dins.read_uint16();
- if (length < 2) {
- debug("Invalid length %Xh at ofs %" + int64.FORMAT + "Xh", length, fins.tell() - 2);
+ if (length < 2 && fins is Seekable) {
+ debug("Invalid length %Xh at ofs %" + int64.FORMAT + "Xh", length,
+ (fins as Seekable).tell() - 2);
return -1;
}