diff --git a/lib/src/util.dart b/lib/src/util.dart index 8f3d5de..4a0db21 100644 --- a/lib/src/util.dart +++ b/lib/src/util.dart @@ -28,6 +28,9 @@ String make_string(List seq) { // Special version to deal with the code in the first 8 bytes of a user comment. // First 8 bytes gives coding system e.g. ASCII vs. JIS vs Unicode. String make_string_uc(List seq) { + if (seq.length <= 8) { + return ""; + } seq = seq.sublist(8); // Of course, this is only correct if ASCII, and the standard explicitly // allows JIS and Unicode. diff --git a/test/util_test.dart b/test/util_test.dart new file mode 100644 index 0000000..c7c44a2 --- /dev/null +++ b/test/util_test.dart @@ -0,0 +1,13 @@ + +import "package:test/test.dart"; +import 'package:exif/src/util.dart'; + +void main() { + test("make_string_uc", () { + expect(make_string_uc([]), equals("")); + expect(make_string_uc([1,2,3,4,5,6,7]), equals("")); + expect(make_string_uc([1,2,3,4,5,6,7,8,9,10]), equals("[9, 10]")); + expect(make_string_uc([1,2,3,4,5,6,7,8,9,10]), equals("[9, 10]")); + expect(make_string_uc([1,2,3,4,5,6,7,8,97,98,99]), equals("abc")); + }); +}