aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2020-03-19 16:15:04 +0100
committerLars Ingebrigtsen2020-03-19 16:17:48 +0100
commitd801d1d8ccae3d8c9ea3d55c27ae16cd28212734 (patch)
treecf25ad2557d091abcc167722bd841512230bef65
parentbed04c502caa8cf0365a0808adb70451b3d8761a (diff)
downloademacs-d801d1d8ccae3d8c9ea3d55c27ae16cd28212734.tar.gz
emacs-d801d1d8ccae3d8c9ea3d55c27ae16cd28212734.zip
Don't have exif bugging out on short strings
* lisp/image/exif.el (exif--direct-ascii-value): New function (bug#40127). (exif--parse-directory): Use it to get the correct values for in-directory (i.e., shorter than 4 octets) strings.
-rw-r--r--lisp/image/exif.el21
-rw-r--r--test/data/image/black-short.jpgbin0 -> 31779 bytes
-rw-r--r--test/lisp/image/exif-tests.el11
3 files changed, 30 insertions, 2 deletions
diff --git a/lisp/image/exif.el b/lisp/image/exif.el
index 642bc58321c..065456dc318 100644
--- a/lisp/image/exif.el
+++ b/lisp/image/exif.el
@@ -72,7 +72,8 @@
72 (283 y-resolution) 72 (283 y-resolution)
73 (296 resolution-unit) 73 (296 resolution-unit)
74 (305 software) 74 (305 software)
75 (306 date-time)) 75 (306 date-time)
76 (315 artist))
76 "Alist of tag values and their names.") 77 "Alist of tag values and their names.")
77 78
78(defconst exif--orientation 79(defconst exif--orientation
@@ -216,7 +217,10 @@ If the orientation isn't present in the data, return nil."
216 (+ (1+ value) length))) 217 (+ (1+ value) length)))
217 ;; The value is stored directly 218 ;; The value is stored directly
218 ;; in the directory. 219 ;; in the directory.
219 value) 220 (if (eq (car field-format) 'ascii)
221 (exif--direct-ascii-value
222 value (1- length) le)
223 value))
220 (car field-format) 224 (car field-format)
221 le))))) 225 le)))))
222 (let ((next (exif--read-number 4 le))) 226 (let ((next (exif--read-number 4 le)))
@@ -231,6 +235,19 @@ If the orientation isn't present in the data, return nil."
231 ;; We've reached the end of the directories. 235 ;; We've reached the end of the directories.
232 dir)))) 236 dir))))
233 237
238(defun exif--direct-ascii-value (value bytes le)
239 "Make VALUE into a zero-terminated string.
240VALUE is an integer representing BYTES characters."
241 (with-temp-buffer
242 (set-buffer-multibyte nil)
243 (if le
244 (dotimes (i bytes)
245 (insert (logand (lsh value (* i -8)) 255)))
246 (dotimes (i bytes)
247 (insert (logand (lsh value (* (- (1- bytes) i) -8)) 255))))
248 (insert 0)
249 (buffer-string)))
250
234(defun exif--process-value (value type le) 251(defun exif--process-value (value type le)
235 "Do type-based post-processing of the value." 252 "Do type-based post-processing of the value."
236 (cl-case type 253 (cl-case type
diff --git a/test/data/image/black-short.jpg b/test/data/image/black-short.jpg
new file mode 100644
index 00000000000..02a5b0b72ef
--- /dev/null
+++ b/test/data/image/black-short.jpg
Binary files differ
diff --git a/test/lisp/image/exif-tests.el b/test/lisp/image/exif-tests.el
index cb7c9ecbda6..8a2231106f0 100644
--- a/test/lisp/image/exif-tests.el
+++ b/test/lisp/image/exif-tests.el
@@ -41,4 +41,15 @@
41 (should (equal (exif-elem exif 'orientation) 1)) 41 (should (equal (exif-elem exif 'orientation) 1))
42 (should (equal (exif-elem exif 'x-resolution) '(180 . 1))))) 42 (should (equal (exif-elem exif 'x-resolution) '(180 . 1)))))
43 43
44(ert-deftest test-exif-parse-short ()
45 (let ((exif (exif-parse-file (test-image-file "black-short.jpg"))))
46 (should (equal (exif-elem exif 'make) "thr"))
47 (should (equal (exif-elem exif 'model) "four"))
48 (should (equal (exif-elem exif 'software) "em"))
49 (should (equal (exif-elem exif 'artist) "z"))))
50
51(ert-deftest test-exit-direct-ascii-value ()
52 (equal (exif--direct-ascii-value 28005 2 t) (string ?e ?m 0))
53 (equal (exif--direct-ascii-value 28005 2 nil) (string ?m ?e 0)))
54
44;;; exif-tests.el ends here 55;;; exif-tests.el ends here