[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-27 d801d1d: Don't have exif bugging out on short strings
From: |
Lars Ingebrigtsen |
Subject: |
emacs-27 d801d1d: Don't have exif bugging out on short strings |
Date: |
Thu, 19 Mar 2020 11:18:10 -0400 (EDT) |
branch: emacs-27
commit d801d1d8ccae3d8c9ea3d55c27ae16cd28212734
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>
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.
---
lisp/image/exif.el | 21 +++++++++++++++++++--
test/data/image/black-short.jpg | Bin 0 -> 31779 bytes
test/lisp/image/exif-tests.el | 11 +++++++++++
3 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/lisp/image/exif.el b/lisp/image/exif.el
index 642bc58..065456d 100644
--- a/lisp/image/exif.el
+++ b/lisp/image/exif.el
@@ -72,7 +72,8 @@
(283 y-resolution)
(296 resolution-unit)
(305 software)
- (306 date-time))
+ (306 date-time)
+ (315 artist))
"Alist of tag values and their names.")
(defconst exif--orientation
@@ -216,7 +217,10 @@ If the orientation isn't present in the data, return nil."
(+ (1+ value) length)))
;; The value is stored directly
;; in the directory.
- value)
+ (if (eq (car field-format) 'ascii)
+ (exif--direct-ascii-value
+ value (1- length) le)
+ value))
(car field-format)
le)))))
(let ((next (exif--read-number 4 le)))
@@ -231,6 +235,19 @@ If the orientation isn't present in the data, return nil."
;; We've reached the end of the directories.
dir))))
+(defun exif--direct-ascii-value (value bytes le)
+ "Make VALUE into a zero-terminated string.
+VALUE is an integer representing BYTES characters."
+ (with-temp-buffer
+ (set-buffer-multibyte nil)
+ (if le
+ (dotimes (i bytes)
+ (insert (logand (lsh value (* i -8)) 255)))
+ (dotimes (i bytes)
+ (insert (logand (lsh value (* (- (1- bytes) i) -8)) 255))))
+ (insert 0)
+ (buffer-string)))
+
(defun exif--process-value (value type le)
"Do type-based post-processing of the value."
(cl-case type
diff --git a/test/data/image/black-short.jpg b/test/data/image/black-short.jpg
new file mode 100644
index 0000000..02a5b0b
Binary files /dev/null and b/test/data/image/black-short.jpg differ
diff --git a/test/lisp/image/exif-tests.el b/test/lisp/image/exif-tests.el
index cb7c9ec..8a22311 100644
--- a/test/lisp/image/exif-tests.el
+++ b/test/lisp/image/exif-tests.el
@@ -41,4 +41,15 @@
(should (equal (exif-elem exif 'orientation) 1))
(should (equal (exif-elem exif 'x-resolution) '(180 . 1)))))
+(ert-deftest test-exif-parse-short ()
+ (let ((exif (exif-parse-file (test-image-file "black-short.jpg"))))
+ (should (equal (exif-elem exif 'make) "thr"))
+ (should (equal (exif-elem exif 'model) "four"))
+ (should (equal (exif-elem exif 'software) "em"))
+ (should (equal (exif-elem exif 'artist) "z"))))
+
+(ert-deftest test-exit-direct-ascii-value ()
+ (equal (exif--direct-ascii-value 28005 2 t) (string ?e ?m 0))
+ (equal (exif--direct-ascii-value 28005 2 nil) (string ?m ?e 0)))
+
;;; exif-tests.el ends here
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- emacs-27 d801d1d: Don't have exif bugging out on short strings,
Lars Ingebrigtsen <=