Add trusted_file to disable metadata safeguards like PIL size limit.
This commit is contained in:
		
							parent
							
								
									0864572930
								
							
						
					
					
						commit
						ec1197d7ca
					
				
					 1 changed files with 12 additions and 3 deletions
				
			
		|  | @ -1231,12 +1231,17 @@ class Photo(ObjectBase): | ||||||
| 
 | 
 | ||||||
|         self.duration = probe.audio.duration |         self.duration = probe.audio.duration | ||||||
| 
 | 
 | ||||||
|     def _reload_image_metadata(self): |     def _reload_image_metadata(self, trusted_file=False): | ||||||
|  |         _max_pixels = PIL.Image.MAX_IMAGE_PIXELS | ||||||
|  |         if trusted_file: | ||||||
|  |             PIL.Image.MAX_IMAGE_PIXELS = None | ||||||
|         try: |         try: | ||||||
|             image = PIL.Image.open(self.real_path.absolute_path) |             image = PIL.Image.open(self.real_path.absolute_path) | ||||||
|         except (OSError, ValueError): |         except (OSError, ValueError): | ||||||
|             traceback.print_exc() |             traceback.print_exc() | ||||||
|             return |             return | ||||||
|  |         finally: | ||||||
|  |             PIL.Image.MAX_IMAGE_PIXELS = _max_pixels | ||||||
| 
 | 
 | ||||||
|         (self.width, self.height) = image.size |         (self.width, self.height) = image.size | ||||||
|         image.close() |         image.close() | ||||||
|  | @ -1260,9 +1265,13 @@ class Photo(ObjectBase): | ||||||
| 
 | 
 | ||||||
|     @decorators.required_feature('photo.reload_metadata') |     @decorators.required_feature('photo.reload_metadata') | ||||||
|     @worms.atomic |     @worms.atomic | ||||||
|     def reload_metadata(self, hash_kwargs=None) -> None: |     def reload_metadata(self, hash_kwargs=None, trusted_file=False) -> None: | ||||||
|         ''' |         ''' | ||||||
|         Load the file's height, width, etc as appropriate for this type of file. |         Load the file's height, width, etc as appropriate for this type of file. | ||||||
|  | 
 | ||||||
|  |         trusted_file: | ||||||
|  |             If True, we can disable certain safeguards for file parsing, | ||||||
|  |             depending on the file format. | ||||||
|         ''' |         ''' | ||||||
|         log.info('Reloading metadata for %s.', self) |         log.info('Reloading metadata for %s.', self) | ||||||
| 
 | 
 | ||||||
|  | @ -1282,7 +1291,7 @@ class Photo(ObjectBase): | ||||||
|             pass |             pass | ||||||
| 
 | 
 | ||||||
|         elif self.simple_mimetype == 'image': |         elif self.simple_mimetype == 'image': | ||||||
|             self._reload_image_metadata() |             self._reload_image_metadata(trusted_file=trusted_file) | ||||||
| 
 | 
 | ||||||
|         elif self.simple_mimetype == 'video': |         elif self.simple_mimetype == 'video': | ||||||
|             self._reload_video_metadata() |             self._reload_video_metadata() | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue