summaryrefslogtreecommitdiff
path: root/src/photos
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2014-09-23 09:36:45 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2014-09-23 09:36:45 +0200
commit566dc060676b41e1e58a446b7dcc4159e242fee6 (patch)
tree6eaeba1cf78d3f03b8a1d5bfa998eb104ca47425 /src/photos
parent4ea2cc3bd4a7d9b1c54a9d33e6a1cf82e7c8c21d (diff)
Imported Upstream version 0.20.0upstream/0.20.0
Diffstat (limited to 'src/photos')
-rw-r--r--src/photos/BmpSupport.vala11
-rw-r--r--src/photos/GdkSupport.vala7
-rw-r--r--src/photos/JfifSupport.vala7
-rw-r--r--src/photos/PhotoFileFormat.vala4
-rw-r--r--src/photos/PhotoFileSniffer.vala20
-rw-r--r--src/photos/PngSupport.vala11
-rw-r--r--src/photos/RawSupport.vala5
-rw-r--r--src/photos/TiffSupport.vala7
8 files changed, 52 insertions, 20 deletions
diff --git a/src/photos/BmpSupport.vala b/src/photos/BmpSupport.vala
index 546bed2..dbeb64c 100644
--- a/src/photos/BmpSupport.vala
+++ b/src/photos/BmpSupport.vala
@@ -71,14 +71,17 @@ public class BmpSniffer : GdkSniffer {
return true;
}
- public override DetectedPhotoInformation? sniff() throws Error {
+ public override DetectedPhotoInformation? sniff(out bool is_corrupted) throws Error {
+ // Rely on GdkSniffer to detect corruption
+ is_corrupted = false;
+
if (!is_bmp_file(file))
return null;
-
- DetectedPhotoInformation? detected = base.sniff();
+
+ DetectedPhotoInformation? detected = base.sniff(out is_corrupted);
if (detected == null)
return null;
-
+
return (detected.file_format == PhotoFileFormat.BMP) ? detected : null;
}
}
diff --git a/src/photos/GdkSupport.vala b/src/photos/GdkSupport.vala
index 4ca0893..ed2ff63 100644
--- a/src/photos/GdkSupport.vala
+++ b/src/photos/GdkSupport.vala
@@ -34,7 +34,7 @@ public abstract class GdkSniffer : PhotoFileSniffer {
base (file, options);
}
- public override DetectedPhotoInformation? sniff() throws Error {
+ public override DetectedPhotoInformation? sniff(out bool is_corrupted) throws Error {
detected = new DetectedPhotoInformation();
Gdk.PixbufLoader pixbuf_loader = new Gdk.PixbufLoader();
@@ -53,7 +53,7 @@ public abstract class GdkSniffer : PhotoFileSniffer {
// no metadata detected
detected.metadata = null;
}
-
+
if (calc_md5 && detected.metadata != null) {
uint8[]? flattened_sans_thumbnail = detected.metadata.flatten_exif(false);
if (flattened_sans_thumbnail != null && flattened_sans_thumbnail.length > 0)
@@ -102,6 +102,9 @@ public abstract class GdkSniffer : PhotoFileSniffer {
if (calc_md5)
detected.md5 = md5_checksum.get_string();
+ // if size and area are not ready, treat as corrupted file (entire file was read)
+ is_corrupted = !size_ready || !area_prepared;
+
return detected;
}
diff --git a/src/photos/JfifSupport.vala b/src/photos/JfifSupport.vala
index 12ac80a..d721441 100644
--- a/src/photos/JfifSupport.vala
+++ b/src/photos/JfifSupport.vala
@@ -102,11 +102,14 @@ public class JfifSniffer : GdkSniffer {
base (file, options);
}
- public override DetectedPhotoInformation? sniff() throws Error {
+ public override DetectedPhotoInformation? sniff(out bool is_corrupted) throws Error {
+ // Rely on GdkSniffer to detect corruption
+ is_corrupted = false;
+
if (!Jpeg.is_jpeg(file))
return null;
- DetectedPhotoInformation? detected = base.sniff();
+ DetectedPhotoInformation? detected = base.sniff(out is_corrupted);
if (detected == null)
return null;
diff --git a/src/photos/PhotoFileFormat.vala b/src/photos/PhotoFileFormat.vala
index 926254d..2ab2f00 100644
--- a/src/photos/PhotoFileFormat.vala
+++ b/src/photos/PhotoFileFormat.vala
@@ -202,9 +202,9 @@ public enum PhotoFileFormat {
case "tiff":
return PhotoFileFormat.TIFF;
-
+
case "bmp":
- return PhotoFileFormat.BMP;
+ return PhotoFileFormat.BMP;
default:
return PhotoFileFormat.UNKNOWN;
diff --git a/src/photos/PhotoFileSniffer.vala b/src/photos/PhotoFileSniffer.vala
index 8bd6711..3f65ac2 100644
--- a/src/photos/PhotoFileSniffer.vala
+++ b/src/photos/PhotoFileSniffer.vala
@@ -46,7 +46,7 @@ public abstract class PhotoFileSniffer {
calc_md5 = (options & Options.NO_MD5) == 0;
}
- public abstract DetectedPhotoInformation? sniff() throws Error;
+ public abstract DetectedPhotoInformation? sniff(out bool is_corrupted) throws Error;
}
//
@@ -62,6 +62,7 @@ public class PhotoFileInterrogator {
private File file;
private PhotoFileSniffer.Options options;
private DetectedPhotoInformation? detected = null;
+ private bool is_photo_corrupted = false;
public PhotoFileInterrogator(File file,
PhotoFileSniffer.Options options = PhotoFileSniffer.Options.GET_ALL) {
@@ -75,14 +76,27 @@ public class PhotoFileInterrogator {
return detected;
}
+ // Call after interrogate().
+ public bool get_is_photo_corrupted() {
+ return is_photo_corrupted;
+ }
+
public void interrogate() throws Error {
foreach (PhotoFileFormat file_format in PhotoFileFormat.get_supported()) {
PhotoFileSniffer sniffer = file_format.create_sniffer(file, options);
- detected = sniffer.sniff();
- if (detected != null) {
+
+ bool is_corrupted;
+ detected = sniffer.sniff(out is_corrupted);
+ if (detected != null && !is_corrupted) {
assert(detected.file_format == file_format);
break;
+ } else if (is_corrupted) {
+ message("Sniffing halted for %s: potentially corrupted image file", file.get_path());
+ is_photo_corrupted = true;
+ detected = null;
+
+ break;
}
}
}
diff --git a/src/photos/PngSupport.vala b/src/photos/PngSupport.vala
index ffc7faa..2cde6a2 100644
--- a/src/photos/PngSupport.vala
+++ b/src/photos/PngSupport.vala
@@ -69,14 +69,17 @@ public class PngSniffer : GdkSniffer {
return true;
}
- public override DetectedPhotoInformation? sniff() throws Error {
+ public override DetectedPhotoInformation? sniff(out bool is_corrupted) throws Error {
+ // Rely on GdkSniffer to detect corruption
+ is_corrupted = false;
+
if (!is_png_file(file))
return null;
-
- DetectedPhotoInformation? detected = base.sniff();
+
+ DetectedPhotoInformation? detected = base.sniff(out is_corrupted);
if (detected == null)
return null;
-
+
return (detected.file_format == PhotoFileFormat.PNG) ? detected : null;
}
}
diff --git a/src/photos/RawSupport.vala b/src/photos/RawSupport.vala
index bad9572..98bc982 100644
--- a/src/photos/RawSupport.vala
+++ b/src/photos/RawSupport.vala
@@ -163,7 +163,10 @@ public class RawSniffer : PhotoFileSniffer {
base (file, options);
}
- public override DetectedPhotoInformation? sniff() throws Error {
+ public override DetectedPhotoInformation? sniff(out bool is_corrupted) throws Error {
+ // this sniffer doesn't detect corrupted files
+ is_corrupted = false;
+
DetectedPhotoInformation detected = new DetectedPhotoInformation();
GRaw.Processor processor = new GRaw.Processor();
diff --git a/src/photos/TiffSupport.vala b/src/photos/TiffSupport.vala
index decc052..ee8b087 100644
--- a/src/photos/TiffSupport.vala
+++ b/src/photos/TiffSupport.vala
@@ -104,11 +104,14 @@ private class TiffSniffer : GdkSniffer {
base (file, options);
}
- public override DetectedPhotoInformation? sniff() throws Error {
+ public override DetectedPhotoInformation? sniff(out bool is_corrupted) throws Error {
+ // Rely on GdkSniffer to detect corruption
+ is_corrupted = false;
+
if (!is_tiff(file))
return null;
- DetectedPhotoInformation? detected = base.sniff();
+ DetectedPhotoInformation? detected = base.sniff(out is_corrupted);
if (detected == null)
return null;