@@ -40,7 +40,6 @@ static zend_object_handlers finfo_object_handlers;
4040zend_class_entry * finfo_class_entry ;
4141
4242typedef struct _finfo_object {
43- zend_long options ;
4443 struct magic_set * magic ;
4544 zend_object zo ;
4645} finfo_object ;
@@ -203,12 +202,10 @@ PHP_FUNCTION(finfo_open)
203202 zend_restore_error_handling (& zeh );
204203 finfo_object * obj = Z_FINFO_P (object );
205204 obj -> magic = magic ;
206- obj -> options = options ;
207205 } else {
208206 zend_object * zobj = finfo_objects_new (finfo_class_entry );
209207 finfo_object * obj = php_finfo_fetch_object (zobj );
210208 obj -> magic = magic ;
211- obj -> options = options ;
212209 RETURN_OBJ (zobj );
213210 }
214211}
@@ -240,7 +237,6 @@ PHP_FUNCTION(finfo_set_flags)
240237 /* We do not check the return value as it can only ever fail if options contains MAGIC_PRESERVE_ATIME
241238 * and the system neither has utime(3) nor utimes(2). Something incredibly unlikely. */
242239 magic_setflags (Z_FINFO_P (self )-> magic , options );
243- Z_FINFO_P (self )-> options = options ;
244240
245241 RETURN_TRUE ;
246242}
@@ -317,16 +313,18 @@ PHP_FUNCTION(finfo_file)
317313 }
318314
319315 /* Set options for the current file/buffer. */
316+ int old_options = magic_getflags (magic );
320317 if (options ) {
321318 /* We do not check the return value as it can only ever fail if options contains MAGIC_PRESERVE_ATIME
322319 * and the system neither has utime(3) nor utimes(2). Something incredibly unlikely. */
323320 magic_setflags (magic , options );
324321 }
325322
326323 const char * ret_val = php_fileinfo_from_path (magic , path , context );
324+
327325 /* Restore options */
328326 if (options ) {
329- magic_setflags (magic , Z_FINFO_P ( self ) -> options );
327+ magic_setflags (magic , old_options );
330328 }
331329
332330 if (UNEXPECTED (ret_val == NULL )) {
@@ -351,15 +349,18 @@ PHP_FUNCTION(finfo_buffer)
351349 struct magic_set * magic = Z_FINFO_P (self )-> magic ;
352350
353351 /* Set options for the current file/buffer. */
352+ int old_options = magic_getflags (magic );
354353 if (options ) {
354+ /* We do not check the return value as it can only ever fail if options contains MAGIC_PRESERVE_ATIME
355+ * and the system neither has utime(3) nor utimes(2). Something incredibly unlikely. */
355356 magic_setflags (magic , options );
356357 }
357358
358359 const char * ret_val = magic_buffer (magic , ZSTR_VAL (buffer ), ZSTR_LEN (buffer ));
359360
360361 /* Restore options */
361362 if (options ) {
362- magic_setflags (magic , Z_FINFO_P ( self ) -> options );
363+ magic_setflags (magic , old_options );
363364 }
364365
365366 if (UNEXPECTED (ret_val == NULL )) {
0 commit comments