exif 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/ext/exif/data.c +38 -11
  3. data/lib/exif/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e9c95ed5bae94cb0ba692cc6e2c8f78a24919fd0
4
- data.tar.gz: 03eddb0662aefd46ef6d746e6df5e33a70d25df2
3
+ metadata.gz: 8d658dd771d13abedfe7ab02bfede763a0021132
4
+ data.tar.gz: 56327a0dade4446064ffbed2a849836598b891dd
5
5
  SHA512:
6
- metadata.gz: 15be77ed432c2d18fa63b5cdccfeb0349967b8b87851061dd0c296bb4a773e2eedd8e16411896489ca7e70ef4be6df646ed06a70a933f040131985c3bc301492
7
- data.tar.gz: e931603d06c4702e4bfc44bf74eb73b22ae4e2f88b4253c6a1402ec85fcb6f0513bd023a46fb499904e598a5297b6177f562105815a38ff0765c4fe1541fa00d
6
+ metadata.gz: a1e5a4b2d2826d24dcb5d5e2e59a6f1f4df7a2753ed17526b83c236f164d74139f4037833e55f913a5a3dc77f6e32398c9bdf48893f701647305b36ed22980c2
7
+ data.tar.gz: dd5a25648daaa66665ccc0c3ad9b3da78a2f02b1ee2b77c016ad45d082293c61b4df75590f82584722b7806b08add02c98cd8e1aaee13aa9b32dd9d40788645d
@@ -1,6 +1,7 @@
1
1
  #include "data.h"
2
2
  #include "ruby.h"
3
3
 
4
+ #include <libexif/exif-log.h>
4
5
  #include <libexif/exif-data.h>
5
6
  #include <libexif/exif-loader.h>
6
7
  #include <stdint.h>
@@ -171,6 +172,15 @@ static VALUE exif_entry_to_rb_value(ExifEntry *);
171
172
  static VALUE rational_to_num(ExifRational rational);
172
173
  static VALUE srational_to_num(ExifSRational srational);
173
174
 
175
+ static void exif_corrupt_log_func(ExifLog *log, ExifLogCode code,
176
+ const char *domain, const char *format,
177
+ va_list args, void *data) {
178
+ if (code == EXIF_LOG_CODE_CORRUPT_DATA) {
179
+ unsigned int *corrupt = (unsigned int *)data;
180
+ *corrupt = 1;
181
+ }
182
+ }
183
+
174
184
  void init_data() {
175
185
  int length;
176
186
 
@@ -186,21 +196,38 @@ void init_data() {
186
196
 
187
197
  VALUE new (VALUE self, VALUE input) {
188
198
  ExifData *ed;
189
- VALUE read_data;
190
199
 
191
- if (TYPE(input) == T_STRING)
192
- read_data = input;
193
- else if (rb_respond_to(input, rb_intern("read")))
194
- read_data = rb_funcall(input, rb_intern("read"), 0);
195
- else
200
+ if (TYPE(input) != T_STRING && !rb_respond_to(input, rb_intern("read")))
196
201
  rb_raise(rb_eTypeError, "wrong argument type %s (expected String or IO)",
197
202
  rb_obj_classname(input));
198
203
 
199
- ExifLoader *loader = exif_loader_new();
200
- exif_loader_write(loader, (unsigned char *)RSTRING_PTR(read_data),
201
- RSTRING_LEN(read_data));
202
- ed = exif_loader_get_data(loader);
203
- exif_loader_unref(loader);
204
+ if (TYPE(input) == T_STRING) {
205
+ unsigned int corrupt = 0;
206
+ ExifLog *log = exif_log_new();
207
+ exif_log_set_func(log, exif_corrupt_log_func, (void *)&corrupt);
208
+ ed = exif_data_new();
209
+ exif_data_log(ed, log);
210
+ exif_data_load_data(ed, (unsigned char *)RSTRING_PTR(input),
211
+ RSTRING_LEN(input));
212
+ exif_log_unref(log);
213
+ if (corrupt) {
214
+ exif_data_free(ed);
215
+ ed = NULL;
216
+ }
217
+ } else {
218
+ ExifLoader *loader = exif_loader_new();
219
+ VALUE buffer;
220
+ while (1) {
221
+ buffer = rb_funcall(input, rb_intern("read"), 1, INT2FIX(1024));
222
+ if (TYPE(buffer) == T_NIL)
223
+ break;
224
+ if (!exif_loader_write(loader, (unsigned char *)RSTRING_PTR(buffer),
225
+ RSTRING_LEN(buffer)))
226
+ break;
227
+ }
228
+ ed = exif_loader_get_data(loader);
229
+ exif_loader_unref(loader);
230
+ }
204
231
  if (!ed)
205
232
  rb_raise(rb_eNotReadable, "File not readable or no EXIF data in file.");
206
233
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Exif
4
- VERSION = '2.1.0'
4
+ VERSION = '2.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exif
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jian Weihang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-20 00:00:00.000000000 Z
11
+ date: 2017-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler