@@ -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,19 @@ PHP_FUNCTION(finfo_file)
317313 }
318314
319315 /* Set options for the current file/buffer. */
316+ int old_options ;
320317 if (options ) {
318+ old_options = magic_getflags (magic );
321319 /* We do not check the return value as it can only ever fail if options contains MAGIC_PRESERVE_ATIME
322320 * and the system neither has utime(3) nor utimes(2). Something incredibly unlikely. */
323321 magic_setflags (magic , options );
324322 }
325323
326324 const char * ret_val = php_fileinfo_from_path (magic , path , context );
325+
327326 /* Restore options */
328327 if (options ) {
329- magic_setflags (magic , Z_FINFO_P ( self ) -> options );
328+ magic_setflags (magic , old_options );
330329 }
331330
332331 if (UNEXPECTED (ret_val == NULL )) {
@@ -351,15 +350,19 @@ PHP_FUNCTION(finfo_buffer)
351350 struct magic_set * magic = Z_FINFO_P (self )-> magic ;
352351
353352 /* Set options for the current file/buffer. */
353+ int old_options ;
354354 if (options ) {
355+ old_options = magic_getflags (magic );
356+ /* We do not check the return value as it can only ever fail if options contains MAGIC_PRESERVE_ATIME
357+ * and the system neither has utime(3) nor utimes(2). Something incredibly unlikely. */
355358 magic_setflags (magic , options );
356359 }
357360
358361 const char * ret_val = magic_buffer (magic , ZSTR_VAL (buffer ), ZSTR_LEN (buffer ));
359362
360363 /* Restore options */
361364 if (options ) {
362- magic_setflags (magic , Z_FINFO_P ( self ) -> options );
365+ magic_setflags (magic , old_options );
363366 }
364367
365368 if (UNEXPECTED (ret_val == NULL )) {
0 commit comments