Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Unified Diff: ui/file_manager/file_manager/foreground/js/metadata/exif_parser_unittest.js

Issue 968793002: Handle wrongly formatted EXIF string field. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/file_manager/file_manager/foreground/js/metadata/exif_parser_unittest.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/file_manager/file_manager/foreground/js/metadata/exif_parser_unittest.js
diff --git a/ui/file_manager/file_manager/foreground/js/metadata/exif_parser_unittest.js b/ui/file_manager/file_manager/foreground/js/metadata/exif_parser_unittest.js
new file mode 100644
index 0000000000000000000000000000000000000000..eefe242bd222bc8c0ff77acad4f8809e6c745570
--- /dev/null
+++ b/ui/file_manager/file_manager/foreground/js/metadata/exif_parser_unittest.js
@@ -0,0 +1,67 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * Creates a directory with specified tag. This method only supports string
+ * format tag which is longer than 4 characters.
+ * @param {!TypedArray} bytes Bytes to be written.
+ * @param {!ExifEntry} tag An exif entry which will be written.
+ */
+function writeDirectory_(bytes, tag) {
+ assertEquals(2, tag.format);
+ assertTrue(tag.componentCount > 4);
+
+ var byteWriter = new ByteWriter(bytes.buffer, 0);
+ byteWriter.writeScalar(1, 2); // Number of fields.
+
+ byteWriter.writeScalar(tag.id, 2);
+ byteWriter.writeScalar(tag.format, 2);
+ byteWriter.writeScalar(tag.componentCount, 4);
+ byteWriter.forward(tag.id, 4);
+
+ byteWriter.writeScalar(0, 4); // Offset to next IFD.
+
+ byteWriter.resolveOffset(tag.id);
+ byteWriter.writeString(tag.value);
+
+ byteWriter.checkResolved();
+}
+
+/**
+ * Parses exif data and return parsed tags.
+ * @param {!TypedArray} bytes Bytes to be read.
+ * @return {!Object<!Exif.Tag, !ExifEntry>} Tags.
+ */
+function parseExifData_(bytes) {
+ var exifParser = new ExifParser(this);
+ exifParser.log = function(arg) { console.log(arg); };
+ exifParser.vlog = function(arg) { console.log(arg); };
+
+ var tags = {};
+ var byteReader = new ByteReader(bytes.buffer);
+ assertEquals(0, exifParser.readDirectory(byteReader, tags));
+ return tags;
+}
+
+/**
+ * Test case a string doest not end with null character termination.
+ */
+function testWithoutNullCharacterTermination() {
+ // Create a data which doesn't end with null character.
+ var bytes = new Uint8Array(0x10000);
+ writeDirectory_(bytes, {
+ id: 0x10f, // Manufacture.
+ format: 2, // String.
+ componentCount: 11,
+ value: 'Manufacture'
+ });
+
+ // Parse the data.
+ var tags = parseExifData_(bytes);
+
+ // Null character should be added at the end of value.
+ var manufactureTag = tags[0x10f];
+ assertEquals(12, manufactureTag.componentCount);
+ assertEquals('Manufacture\0', manufactureTag.value);
+}
« no previous file with comments | « ui/file_manager/file_manager/foreground/js/metadata/exif_parser_unittest.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698