Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • @darkog no problem. We have /tmp allowed by default on our servers. I you choose a different tmp directory it’s fine by me. Please make sure it gets cleaned regularly to prevent high disk usage over time. This is the exact reason why we prefer /tmp -> it get’s cleaned automatically on every reboot by Linux. Therefore a missing temp directory handling won’t fill up space endlessly, which is a very important thing on shared hosting servers.

    @darkog Thank you! I can confirm that downloading now works with /tmp/ allowed in open_basedir

    @darkog do you need additional information for developing a bugfix?

    I had the same error “copy_failed_ziparchive” today and managed to track down the underlying issue.

    The error happens at classes/class-ip-location-block-util.php inside download_zip() at the line where the zip file gets unpacked.

    } elseif ( 'zip' === $ext && class_exists( 'ZipArchive', false ) ) {
    
    	$tmp = self::get_temp_dir();
    	if ( is_wp_error( $tmp ) ) {
    		throw new Exception(
    			sprintf( __( 'Unable to extract archive. %s', 'ip-location-block' ), $tmp->get_error_message() )
    		);
    	}
    
    	$ret = $fs->unzip_file( $src, $tmp ); // @since  0.2.5
    
    	return array('ret' => $ret, 'error' => is_wp_error( $ret ), 'src' => $src, 'tmp' => $tmp);
    
    	if ( is_wp_error( $ret ) ) {
    		throw new Exception(
    			$ret->get_error_code() . ' ' . $ret->get_error_message()
    		);
    	}
    
    	if ( false === ( $data = $fs->get_contents( $tmp .= basename( $filename ) ) ) ) {
    		throw new Exception(
    			sprintf( __( 'Unable to read <code>%s</code>. Please check the permission.', 'ip-location-block' ), $tmp )
    		);
    	}
    
    	if ( false === $fs->put_contents( $filename, $data ) ) {
    		throw new Exception(
    			sprintf( __( 'Unable to write <code>%s</code>. Please check the permission.', 'ip-location-block' ), $filename )
    		);
    	}
    }

    To be exact $ret = $fs->unzip_file( $src, $tmp ); // @since 0.2.5 triggers the issue.

    I added following code directly after $fs->unzip_file for further debugging

    return array('ret' => $ret, 'error' => is_wp_error( $ret ), 'src' => $src, 'tmp' => $tmp);

    and got following json_decode’d response:

    Array
    (
        [IP2Location] => Array
            (
                [ipv4] => Array
                    (
                        [ret] => Array
                            (
                                [errors] => Array
                                    (
                                        [copy_failed_ziparchive] => Array
                                            (
                                                [0] => The file could not be copied.
                                            )
    
                                    )
    
                                [error_data] => Array
                                    (
                                        [copy_failed_ziparchive] => LICENSE-CC-BY-SA-4.0.TXT
                                    )
    
                            )
    
                        [error] => 1
                        [src] => /tmp/IP2LOCATION-LITE-DB1.BIN-gusQKW.tmp
                        [tmp] => /tmp/
                    )
    
                [ipv6] => Array
                    (
                        [ret] => Array
                            (
                                [errors] => Array
                                    (
                                        [copy_failed_ziparchive] => Array
                                            (
                                                [0] => The file could not be copied.
                                            )
    
                                    )
    
                                [error_data] => Array
                                    (
                                        [copy_failed_ziparchive] => LICENSE-CC-BY-SA-4.0.TXT
                                    )
    
                            )
    
                        [error] => 1
                        [src] => /tmp/IP2LOCATION-LITE-DB1.IPV6_.BIN-61HRmx.tmp
                        [tmp] => /tmp/
                    )
    
            )
    
    )

    As you can see copy_failed_ziparchive points to a LICENSE-CC-BY-SA-4.0.TXT.
    I then checked /tmp/ and found multiple .TXT and other files inside.

    root@webserver:~$ ls -1 /tmp
    glances-root.log
    IP2LOCATION-LITE-DB1.BIN-gusQKW.tmp
    IP2LOCATION-LITE-DB1.IPV6_.BIN-61HRmx.tmp
    LICENSE-CC-BY-SA-4.0.TXT
    README_LITE.TXT
    snap.lxd
    snowscan.lock
    systemd-private-7c58b090b60e4cd6a197223c6bd090a5-apache2.service-nEGI0e
    systemd-private-7c58b090b60e4cd6a197223c6bd090a5-ModemManager.service-V5qjbg
    systemd-private-7c58b090b60e4cd6a197223c6bd090a5-nagios-nrpe-server.service-TmVNUe
    systemd-private-7c58b090b60e4cd6a197223c6bd090a5-netdata.service-KvksBg
    systemd-private-7c58b090b60e4cd6a197223c6bd090a5-ntp.service-8ZLPMf
    systemd-private-7c58b090b60e4cd6a197223c6bd090a5-redis-server.service-defW4g
    systemd-private-7c58b090b60e4cd6a197223c6bd090a5-systemd-logind.service-e4U2ch
    systemd-private-7c58b090b60e4cd6a197223c6bd090a5-systemd-resolved.service-kVaj6f

    I then deleted LICENSE-CC-BY-SA-4.0.TXT and clicked “Download now” again. This time the filename in my debug output changed to README_LITE.TXT.

    So it appears that for every file inside /tmp/ $fs->unzip_file( $src, $tmp ) gets called.

    I think the error could be resolved if $tmp = self::get_temp_dir(); returns a sub directory of /tmp/ instead of /tmp/ itself for ex. /tmp/ip-location-block/ so only files inside /tmp/ip-location-block/ are getting unzipped.

    Further information on following check inside get_temp_dir() function:
    if ( ! file_exists( $dir ) || ! is_writable( $dir ) ) {

    We configured our php.ini‘s open_basedir the following way:
    open_basedir = /www/customer8482:/usr/local/session:/usr/share/php:/tmp:/usr/bin/pdfinfo:/usr/bin/pdftotext

    So /tmp/ is within open_basedir and therefore accessible and via linux default /tmp/ behaviour also writable to anyone.

    The check mentioned before skips his subroutine in which a path to a sub directory inside /wp-content/uploads/ folder is constructed and therefore does return trailingslashit( $dir ); which leads to /tmp/ inside $tmp parameter for $ret = $fs->unzip_file( $src, $tmp ); // @since 0.2.5

    Please ask if you need more info about my server configuration/environment.

    Currently using:
    Ubuntu 20.04 LTS Server
    PHP 8.0 with FPM

Viewing 4 replies - 1 through 4 (of 4 total)