Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when parsing Olympus microscope files #65

Closed
fabioperrella opened this issue Sep 9, 2020 · 3 comments
Closed

Error when parsing Olympus microscope files #65

fabioperrella opened this issue Sep 9, 2020 · 3 comments

Comments

@fabioperrella
Copy link
Contributor

Hi,

First of all, thanks for all your work with that gem!

We found an error when parsing files from Olympus microscope (I'm not 100% sure about that orign, more details below).

An example:

$ exifr file3.jpg
Traceback (most recent call last):
        17: from /Users/fabioperrella/.rbenv/versions/2.6.5/bin/exifr:23:in `<main>'
        16: from /Users/fabioperrella/.rbenv/versions/2.6.5/bin/exifr:23:in `load'
        15: from /Users/fabioperrella/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/exifr-1.3.6/bin/exifr:53:in `<top (required)>'
        14: from /Users/fabioperrella/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/exifr-1.3.6/bin/exifr:53:in `each'
        13: from /Users/fabioperrella/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/exifr-1.3.6/bin/exifr:55:in `block in <top (required)>'
        12: from /Users/fabioperrella/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/exifr-1.3.6/bin/exifr:8:in `pp_jpeg'
        11: from /Users/fabioperrella/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/exifr-1.3.6/bin/exifr:8:in `new'
        10: from /Users/fabioperrella/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/exifr-1.3.6/lib/exifr/jpeg.rb:34:in `initialize'
         9: from /Users/fabioperrella/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/exifr-1.3.6/lib/exifr/jpeg.rb:34:in `open'
         8: from /Users/fabioperrella/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/exifr-1.3.6/lib/exifr/jpeg.rb:34:in `block in initialize'
         7: from /Users/fabioperrella/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/exifr-1.3.6/lib/exifr/jpeg.rb:124:in `examine'
         6: from /Users/fabioperrella/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/exifr-1.3.6/lib/exifr/jpeg.rb:124:in `new'
         5: from /Users/fabioperrella/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/exifr-1.3.6/lib/exifr/tiff.rb:377:in `initialize'
         4: from /Users/fabioperrella/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/exifr-1.3.6/lib/exifr/tiff.rb:647:in `open'
         3: from /Users/fabioperrella/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/exifr-1.3.6/lib/exifr/tiff.rb:384:in `block in initialize'
         2: from /Users/fabioperrella/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/exifr-1.3.6/lib/exifr/tiff.rb:384:in `map'
         1: from /Users/fabioperrella/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/exifr-1.3.6/lib/exifr/tiff.rb:387:in `block (2 levels) in initialize'
/Users/fabioperrella/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/exifr-1.3.6/lib/exifr/tiff.rb:387:in `+': no implicit conversion of Integer into String (TypeError)

For this file, I run exiftool and got this output:

$ exiftool file3.jpg
ExifTool Version Number         : 12.00
File Name                       : file3.jpg
Directory                       : .
File Size                       : 2.1 MB
File Modification Date/Time     : 2020:09:09 16:07:00-03:00
File Access Date/Time           : 2020:09:09 16:07:46-03:00
File Inode Change Date/Time     : 2020:09:09 16:07:45-03:00
File Permissions                : rw-r--r--
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
JFIF Version                    : 1.01
Exif Byte Order                 : Little-endian (Intel, II)
Make                            : Olympus Soft Imaging Solutions
Camera Model Name               : XC30
Orientation                     : Horizontal (normal)
X Resolution                    : 72
Y Resolution                    : 72
Resolution Unit                 : inches
Modify Date                     : 2017:03:03 14:54:31
Artist                          : Uni Vest Arad
Exposure Time                   : 1/1258
Exif Version                    : 0210
Create Date                     : 2017:03:03 14:54:31
Aperture Value                  : 1.0
Subject Distance                : 0.017 m
Metering Mode                   : Average
Flashpix Version                : 0100
Color Space                     : sRGB
Exif Image Width                : 2080
Exif Image Height               : 1544
Exposure Mode                   : Manual
GPS Version ID                  : 33554432
Compression                     : JPEG (old-style)
Thumbnail Offset                : 285 246 285 249 30 97 30 35 33 34 34 34 33 35 34 34 34 35 35 35 36 37 42 38 37 37 37 37 45 41 41 39 42 47 45 48 48 47 45 47 47 49 52 58 53 49 50 56 51 47 47 54 63 54 56 59 59 61 61 61 49 53 64 66 64 60 66 58 60 61 60 285 249 30 97 31 35 35 35 37 36 37 44 38 38 44 60 50 47 50 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 60 285 222 30 47 38 30 101 30 126 33 31 64 30 32 47 31 33 47 31 285 226 30 61 30 30 31 35 31 31 31 31 31 31 30 30 30 30 30 30 30 30 31 32 33 34 35 36 37 38 39 40 41 285 226 30 211 46 30 32 31 33 33 32 34 33 35 35 34 34 30 30 31 155 31 32 33 30 34 47 35 48 63 79 95 36 49 111 127 37 64 143 50 80 159 175 191 38 65 96 207 223 51 112 239 270 66 81 128 144 160 39 40 52 53 54 55 56 67 68 69 70 71 72 82 83 84 85 86 87 88 97 98 99 100 101 102 103 104 113 114 115 116 117 118 119 120 129 130 131 132 133 134 135 136 145 146 147 148 149 150 151 152 161 162 163 164 165 166 167 168 176 177 178 179 180 181 182 183 184 192 193 194 195 196 197 198 199 200 208 209 210 211 212 213 214 215 216 224 225 226 227 228 229 230 231 232 240 241 242 243 244 245 246 247 248 255 256 257 258 259 260 261 262 263 264 271 272 273 274 275 276 277 278 279 280 285 226 30 61 31 30 33 31 31 31 31 31 31 31 31 31 30 30 30 30 30 30 31 32 33 34 35 36 37 38 39 40 41 285 226 30 211 47 30 32 31 32 34 34 33 34 37 35 34 34 30 31 32 149 30 31 32 33 47 34 35 63 79 36 48 95 111 37 127 143 49 64 80 159 38 50 96 175 191 207 223 39 65 81 112 270 51 128 144 239 40 52 66 82 255 67 271 53 54 55 56 68 69 70 71 72 83 84 85 86 87 88 97 98 99 100 101 102 103 104 113 114 115 116 117 118 119 120 129 130 131 132 133 134 135 136 145 146 147 148 149 150 151 152 160 161 162 163 164 165 166 167 168 176 177 178 179 180 181 182 183 184 192 193 194 195 196 197 198 199 200 208 209 210 211 212 213 214 215 216 224 225 226 227 228 229 230 231 232 240 241 242 243 244 245 246 247 248 256 257 258 259 260 261 262 263 264 272 273 274 275 276 277 278 279 280 285 248 30 42 33 31 30 32 47 33 47 30 93 30 275 281 263 192 219 283 237 187 258 247 191 32 122 32 190 220 103 65 148 151 258 152 142 95 280 165 67 202 277 175 227 51 190 281 51 162 125 228 156 273 31 229 152 63 213 163 128 176 273 111 175 107 218 172 124 82 141 178 187 234 102 230 257 37 174 79 172 250 258 258 182 132 180 281 119 218 52 174 194 180 212 79 198 80 231 187 194 144 38 123 219 100 101 204 45 241 87 195 262 149 205 75 181 275 273 130 116 180 233 156 171 35 198 49 249 96 104 151 172 168 97 30 142 95 54 258 176 44 155 216 60 214 138 148 176 74 203 131 136 272 98 245 101 260 182 207 57 150 66 154 193 37 87 54 264 45 37 188 196 210 195 119 282 191 127 193 94 52 67 54 176 128 96 172 89 33 173 241 54 284 210 147 148 177 266 240 228 273 86 49 73 97 166 175 97 144 214 228 256 143 214 258 186 170 126 84 150 30 184 194 268 232 219 274 125 245 199 105 107 215 213 88 163 223 163 257 176 238 232 206 229 259 206 74 92 148 99 236 145 223 272 223 69 199 230 265 177 121 188 111 84 271 198 142 59 55 103 34 140 258 144 101 59 278 285 30 45 138 43 71 129 212 47 121 194 239 215 163 242 220 236 164 128 101 268 228 144 103 115 38 78 87 279 108 143 184 252 212 177 155 190 132 175 106 225 74 249 144 225 170 60 44 87 54 90 152 281 239 91 274 82 179 246 228 119 65 117 218 186 229 139 272 171 252 133 232 53 135 140 103 231 30 127 173 241 252 179 256 168 254 193 122 99 176 232 111 97 196 103 125 181 87 264 45 66 47 274 280 243 199 114 207 42 104 39 78 200 65 222 90 144 121 221 156 157 269 189 136 190 276 240 251 121 106 212 172 193 234 106 201 70 233 194 163 101 235 161 263 268 153 31 265 183 106 162 268 235 246 180 39 74 128 111 259 212 246 239 181 134 54 58 142 100 86 264 86 200 56 211 192 195 206 137 147 102 117 93 219 129 231 225 42 133 188 88 267 66 188 222 275 203 86 244 86 191 102 178 180 71 61 124 195 160 280 189 228 200 109 142 234 202 123 40 76 33 63 229 94 95 54 265 245 279 130 114 68 145 95 220 139 42 245 84 231 89 248 129 233 103 51 148 175 65 157 44 104 179 59 79 264 37 127 172 143 97 248 231 55 47 196 276 78 199 38 234 258 181 37 37 161 189 125 112 93 120 130 118 180 254 215 134 119 65 128 246 138 141 106 261 137 154 221 149 241 196 102 228 152 128 203 235 82 189 130 163 122 179 132 69 259 86 236 238 88 130 58 33 229 125 244 203 185 264 184 72 99 58 213 48 139 148 150 268 164 240 65 236 255 54 93 226 222 142 45 212 142 143 186 147 203 116 121 105 73 123 176 103 212 92 118 259 220 133 275 66 277 277 283 136 176 123 252 155 167 115 115 99 234 191 183 122 170 267 112 121 37 133 112 143 172 79 278 168 196 212 213 85 144 279 213 141 61 181 58 176 131 168 258 139 259 94 261 269 48 39 90 31 242 143 111 215 58 204 109 123 46 181 277 277 152 170 96 57 55 127 168 247 223 246 238 206 132 131 248 143 262 30 236 87 55 267 114 196 216 137 121 138 90 173 74 264 80 183 142 194 199 223 128 38 33 33 170 42 30 151 230 250 246 227 169 212 211 208 164 54 203 38 213 159 143 213 170 268 111 173 216 37 138 153 153 115 162 208 80 205 248 58 74 135 217 160 113 183 80 30 33 175 176 157 76 158 144 88 248 135 57 76 115 241 97 84 236 54 82 235 55 140 85 182 140 253 259 113 62 223 40 250 207 222 61 63 62 46 81 170 126 44 161 187 43 73 112 160 261 39 41 98 121 189 251 226 246 30 127 144 31 65 75 241 58 126 33 229 214 201 199 183 65 182 211 214 102 259 133 89 282 223 159 211 110 257 199 35 167 155 161 148 94 59 81 242 54 82 128 270 210 55 175 160 51 79 193 130 71 222 35 213 283 94 54 62 170 171 253 122 213 200 217 72 245 169 175 240 231 260 162 42 194 221 55 40 201 233 60 247 229 95 177 263 249 66 275 196 263 201 66 112 66 104 132 174 48 223 187 206 53 62 257 241 69 163 283 153 275 50 257 185 72 98 46 106 223 242 104 264 50 65 58 254 272 31 261 206 90 143 189 224 210 69 184 73 153 127 261 127 242 76 149 126 126 155 37 106 273 284 68 209 132 43 85 268 180 63 73 50 208 233 63 144 112 78 118 44 168 79 186 30 88 274 237 145 237 59 137 80 281 80 166 159 162 98 67 69 142 131 66 49 210 254 186 143 228 89 271 278 256 197 176 100 163 240 98 57 41 76 39 59 96 258 152 285 30 76 89 277 200 277 85 132 70 101 180 196 96 236 31 172 106 199 30 58 130 33 222 58 280 128 162 40 90 216 175 250 105 54 74 39 141 92 85 126 154 178 231 110 102 128 87 112 80 143 278 271 275 200 203 157 137 149 155 141 57 41 160 55 154 215 36 231 40 71 90 42 161 264 125 55 229 33 87 83 74 169 50 212 34 55 190 174 217 267 178 276 116 37 145 140 231 59 30 237 141 124 275 189 156 119 52 54 191 179 257 175 175 227 215 74 51 259 145 173 74 42 272 87 264 153 129 188 45 83 51 145 118 100 280 185 72 244 264 207 269 219 179 176 68 147 130 90 55 258 230 263 265 160 102 222 257 69 242 40 160 264 261 142 171 130 38 261 55 281 86 258 70 236 38 250 86 75 249 205 54 140 190 58 120 224 118 263 230 181 213 79 88 161 207 195 183 160 163 42 38 30 126 152 254 144 144 145 242 188 72 220 173 196 95 261 155 203 129 147 30 38 242 81 130 127 144 31 249 170 44 197 173 157 203 96 155 106 181 72 217 53 103 207 246 43 276 192 239 179 171 108 92 123 191 117 89 216 61 122 176 109 112 152 260 191 243 269 90 275 135 132 163 258 167 31 146 162 101 273 274 54 57 121 199 140 100 89 261 33 215 203 119 148 123 251 83 207 87 160 62 90 222 45 35 217 77 255 223 93 270 61 152 196 138 75 112 133 211 211 118 244 90 128 141 182 207 37 33 161 237 142 100 101 60 279 235 40 123 223 107 87 124 125 240 78 211 70 260 155 221 127 163 38 189 136 65 80 269 80 58 61 178 42 272 30 30 261 268 257 65 191 136 102 67 172 260 113 51 186 100 150 254 226 116 241 65 101 164 143 161 245 66 170 174 53 263 223 237 111 152 271 223 168 109 62 78 133 113 54 250 81 172 80 101 87 55 65 172 182 58 133 238 260 263 239 279 85 139 73 138 81 182 225 200 165 127 158 197 259 223 34 271 214 226 37 212 144 88 244 167 251 59 79 152 57 43 66 204 34 212 46 70 123 269 138 203 209 63 78 226 130 254 270 194 72 254 257 159 267 168 165 226 141 82 73 81 250 52 164 64 171 208 109 78 48 190 179 110 148 172 193 145 71 275 254 172 136 43 47 162 34 251 191 71 34 134 226 55 54 72 158 249 40 199 54 279 95 236 86 230 57 37 62 143 109 179 93 210 126 101 214 181 76 202 80 204 149 52 233 165 72 100 78 86 171 164 88 112 247 176 283 231 52 130 218 161 233 133 167 179 183 191 113 258 101 175 236 245 129 237 191 276 59 155 153 114 241 194 281 99 216 236 37 183 144 200 272 236 202 149 44 30 122 58 261 43 158 45 59 216 172 136 89 201 94 48 47 141 83 228 277 226 140 208 84 51 104 77 178 108 143 277 230 127 229 72 249 144 81 238 235 136 133 164 247 176 35 173 267 104 154 212 117 154 201 129 233 34 60 165 260 98 90 175 253 90 161 99 179 159 67 232 113 165 112 186 248 121 233 72 151 266 133 35 131 101 118 245 235 236 104 174 109 150 247 214 93 251 280 113 120 115 215 214 209 272 68 182 95 58 100 260 234 180 132 89 181 57 191 127 217 260 143 172 36 55 206 54 130 143 109 207 163 108 175 153 139 144 130 281 66 34 235 31 69 44 84 158 279 237 122 188 114 254 271 161 173 120 123 72 132 118 124 239 222 53 180 94 91 206 76 151 236 46 200 181 281 225 174 191 209 231 91 159 260 274 262 134 280 246 263 75 139 248 73 265 209 65 279 207 236 115 242 78 58 46 38 65 92 186 33 267 177 237 127 136 135 55 40 199 126 192 97 158 251 84 285 30 275 237 136 164 113 216 118 182 47 223 284 147 66 270 227 145 140 127 214 171 66 171 228 55 122 130 61 224 215 141 250 255 155 57 80 259 211 281 68 195 90 244 237 220 268 259 84 98 85 48 111 37 66 212 109 65 87 261 283 190 36 88 242 176 85 176 171 35 192 209 207 177 261 233 130 209 143 175 177 275 55 93 284 216 187 203 48 251 133 84 46 225 50 272 69 34 161 273 61 205 213 90 115 63 138 228 87 63 176 251 193 169 193 259 159 35 92 273 274 54 67 172 101 205 234 229 83 117 82 221 80 73 235 206 139 137 160 51 189 34 100 148 204 46 51 35 220 138 271 217 42 37 59 100 99 92 255 48 89 134 259 118 251 56 254 210 182 140 55 109 154 271 222 57 186 274 269 265 159 115 268 191 53 73 53 183 74 112 151 241 66 269 49 157 42 87 40 36 91 78 121 87 59 280 270 72 233 51 221 115 68 243 127 215 62 94 239 55 80 201 60 97 47 228 81 175 228 91 100 88 145 115 145 105 82 232 174 248 37 49 101 142 66 147 73 218 228 173 211 119 223 132 69 207 254 214 55 276 261 211 103 141 63 121 89 249 214 59 132 163 154 228 38 161 201 280 33 188 195 169 58 241 202 195 273 47 242 227 74 112 235 52 52 107 281 245 233 42 229 157 66 143 236 102 267 222 231 256 200 53 214 56 91 248 121 99 167 218 271 78 119 145 272 274 251 222 231 89 108 150 55 90 152 175 108 259 91 130 204 135 269 48 101 155 147 46 79 218 176 151 111 36 228 81 277 97 129 205 69 213 221 219 84 247 259 189 112 215 232 38 241 42 239 70 170 199 67 130 131 74 153 186 160 93 97 252 162 53 80 135 79 230 238 194 209 225 76 276 45 224 189 185 150 140 91 80 88 149 235 81 103 153 215 76 220 249 72 202 52 239 65 165 80 217 140 34 207 140 81 222 33 86 258 130 254 49 249 49 153 43 262 185 63 240 83 57 57 198 197 52 203 64 283 172 95 221 70 101 232 108 143 159 186 258 78 277 86 280 114 237 194 203 224 99 90 207 162 179 179 94 247 65 84 114 80 206 59 165 99 59 221 180 137 85 224 164 71 83 81 207 223 107 272 228 175 133 259 115 54 77 229 156 106 154 186 275 86 265 123 164 102 58 241 177 259 152 49 120 156 236 148 98 30 139 38 193 207 256 196 37 198 90 168 70 202 108 133 206 129 71 211 215 59 199 176 76 96 201 273 161 231 276 277 284 114 111 94 168 193 104 241 161 52 52 231 214 277 276 222 257 263 227 113 180 237 110 105 215 243 51 68 160 254 48 235 214 32 39 57 108 95 230 86 54 222 254 143 269 99 50 268 239 142 203 76 216 171 242 67 172 71 197 207 225 69 184 166 175 158 221 73 62 37 72 78 100 45 125 108 192 199 262 264 75 193 134 203 128 157 90 236 202 97 189 175 94 54 62 126 273 272 176 81 242 271 188 160 168 72 205 191 245 54 205 133 235 259 145 156 240 55 128 180 100 133 36 81 187 168 87 222 236 152 285 30 188 214 267 184 201 201 97 149 72 101 51 216 50 159 118 165 118 258 38 227 104 186 47 229 34 60 152 172 178 111 110 189 113 175 107 273 145 55 52 276 188 68 213 185 235 240 274 285 30 45 103 49 84 272 248 164 203 90 80 180 248 50 254 101 135 62 249 158 219 273 174 150 262 136 236 175 145 256 281 209 187 125 101 238 82 265 144 272 228 252 100 209 83 226 278 116 131 101 114 281 72 191 116 224 206 234 168 96 213 62 78 71 99 51 149 214 196 249 185 133 285 247
Thumbnail Length                : 3312
Image Width                     : 2080
Image Height                    : 1544
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Aperture                        : 1.0
Image Size                      : 2080x1544
Megapixels                      : 3.2
Shutter Speed                   : 1/1258
Warning                         : RawConv ThumbnailImage: Argument "285 246 285 249 30 97 30 35 33 34 34 34 33 35 34 34 34 3..." isn't numeric in numeric ge (>=)
Thumbnail Image                 : (Binary data 3312 bytes, use -b option to extract)

The error is raised because the start is not an integer at this point:

image

I noticed that exiftool also warns about that:

Warning: RawConv ThumbnailImage: Argument "285 246 285 249 30 97 30 35 33 34 34 34 33 35 34 34 34 3..."
 isn't numeric in numeric ge (>=)

At this moment, I can't share the file that I used to test, because I got it from the production server and it belongs to a customer. I'm trying to ask for permission to use it as a fixture.

Would it be possible to change something to avoid raising this error?

Maybe detecting that it's not a number and skipping like this:

@jpeg_thumbnails = @ifds.map do |v|
  if v.jpeg_interchange_format.is_a(Integer) && v.jpeg_interchange_format_length.is_a?(Integer)  # <---- my suggestion
    start, length = v.jpeg_interchange_format, v.jpeg_interchange_format_length
    data[start..(start + length)]
  end
end.compact
@remvee
Copy link
Owner

remvee commented Sep 9, 2020

Thanks for reporting this! You solution looks fine. Let's include some logging too:

        @jpeg_thumbnails = @ifds.map do |v|
          if v.jpeg_interchange_format && v.jpeg_interchange_format_length
            start, length = v.jpeg_interchange_format, v.jpeg_interchange_format_length
            if Integer === start && Integer === length
              data[start..(start + length)]
            else
              EXIFR.logger.warn("Non numeric JpegInterchangeFormat data")
              nil
            end
          end
        end.compact

Can you make a PR? I'd like a test case with a fixture but this seems so obvious, I'll accept it without one too.

@fabioperrella
Copy link
Contributor Author

great, I will do it tomorrow!

remvee pushed a commit that referenced this issue Sep 11, 2020
Signed-off-by: Remco van 't Veer <remco@remworks.net>
@remvee
Copy link
Owner

remvee commented Sep 11, 2020

Fixed by #66

@remvee remvee closed this as completed Sep 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants