AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   WRBot Segmentation fault (Server crash on map load) (https://forums.alliedmods.net/showthread.php?t=308434)

wAyz 06-20-2018 06:26

WRBot Segmentation fault (Server crash on map load)
 
Hello,

I'm using "WRBot Auto" from kraster (https://xtreme-jumps.eu/e107_plugins...c.php?364070.0) for my KZ Server

Unfortunately nearly 50% of available KZ Maps are getting crashed by this plugin due to a segmentation fault. Crash Log:
Aside from that plugin's really impressive so it would be a waste to not fix this. Hope someone has the knowledge to help me.

Code:

L 06/20/2018 - 08:55:03: [AmxxArch] Processing addons/amxmodx/data/hm_timeattack_LeblE_0004.71.rar addons/amxmodx/data/demo0.dem
! rar.c:214: RAR 5 format isn't supported
! _7z.c:191: 7z support requires 7z SDK (define HAVE_7Z)
Segmentation fault (core dumped)
BFD: Warning: /opt/sell/srv311220/core is truncated: expected core file size >= 185425920, found: 1069056.
Cannot access memory at address 0xf77af908
Cannot access memory at address 0xf77af904
Failed to read a valid object file image from memory.
Cannot access memory at address 0xf77af908
Cannot access memory at address 0xf77af904
debug.cmds:4: Error in sourced command file:
Cannot access memory at address 0xec7fbaf0
email debug.log to [email protected]
Wed Jun 20 08:55:03 CEST 2018: Server restart in 10 seconds

Got 3 other maps as an example, 1st one is working, 2nd/3rd crashing server.

https://i.imgur.com/SblELgG.jpg

Kushfield 06-21-2018 11:12

Re: WRBot Segmentation fault (Server crash on map load)
 
It seems like the module used for extracting .RAR archives only supports some types of them. When it fails to extract, the failure never gets passed to the plugin which continues trying to handle the newly extracted files (that don't exist).

To prevent this from happening, you'd need to add a check to make sure the files actually exist after extraction.

Changing this:
PHP Code:

public bool:is_valid_demo_filefile )
{
    
fseekfile0SEEK_END );
    new 
header_size ftellfile );


    if ( 
header_size 544 )
    {
        return(
false);
    }

    
fseekfile0SEEK_SET );
    new 
signature[6];

    
fread_blocksfilesignaturesizeof(signature), BLOCK_CHAR );

    if ( !
contain"HLDEMO"signature ) )
    {
        return(
false);
    }

    return(
true);


... to this:
PHP Code:

public bool:is_valid_demo_filefile )
{
    if ( !
file )
    {
        return(
false);
    }
    
    
fseekfile0SEEK_END );
    new 
header_size ftellfile );


    if ( 
header_size 544 )
    {
        return(
false);
    }

    
fseekfile0SEEK_SET );
    new 
signature[6];

    
fread_blocksfilesignaturesizeof(signature), BLOCK_CHAR );

    if ( !
contain"HLDEMO"signature ) )
    {
        return(
false);
    }

    return(
true);


should do the job.

If your goal is to make the bot work for all maps though, I'm afraid it's much more complicated than that, since AFAIK there are no other modules for extracting archives, so you'd need to develop one that works for all RAR types yourself. Either that, or repackage all the bad demos into the default RAR format.

wAyz 06-21-2018 23:52

Re: WRBot Segmentation fault (Server crash on map load)
 
Thanks for your code, unluckily server is still crashing on mapchange. Anyway gotta wait for someone to be able to fix unsupported rar format.

Kushfield 06-22-2018 08:14

Re: WRBot Segmentation fault (Server crash on map load)
 
Quote:

Originally Posted by wAyz (Post 2598581)
Thanks for your code, unluckily server is still crashing on mapchange. Anyway gotta wait for someone to be able to fix unsupported rar format.

Ah bummer, I guess something is wrong with the AmxxArch module itself as well then, making the server crash when it runs into an unsupported file format. Unfortunately I won't be able to help too much with that, since I don't have any C++ knowledge, but after having a quick look, I'd guess the problem lies here:
PHP Code:

// File: AmxxZip.cpp
// Line: 234
void extract(const char *filename, const char *dest)
{
    
ar_stream *stream NULL;
    
ar_archive *ar NULL;
    
int entry_count 1;
    
int entry_skips 0;
    
int error_step 1;
    
stream ar_open_file(filename);
    
ar ar_open_any_archive(streamstrrchr(filename'.'));
    
FILEdestfile fopen(dest"wb");;
    while (
ar_parse_entry(ar)) {
        
size_t size ar_entry_get_size(ar);
        while (
size 0) {
            
unsigned char buffer[1024];
            
size_t count size sizeof(buffer) ? size sizeof(buffer);
            if (!
ar_entry_uncompress(arbuffercount))
                break;

            
fwrite(buffersizeof(char), countdestfile);
            
size -= count;
        }
        if (
size 0) {
            
fprintf(stderr"Warning: Failed to uncompress... skipping\n");
            
entry_skips++;
        }
    }
    
error_step entry_skips 1000 entry_skips 0;
    
fclose(destfile);
    
ar_close_archive(ar);
    
ar_close(stream);
    return;


----->
PHP Code:

// File: AmxxZip.cpp
// Line: 234
void extract(const char *filename, const char *dest)
{
    
ar_stream *stream NULL;
    
ar_archive *ar NULL;
    
stream ar_open_file(filename);
    
ar ar_open_any_archive(streamstrrchr(filename'.'));
    if (!
ar)
    {
        
MF_Log("Warning: Unable to extract %s - unsupported format"filename);
    }
    else
    {
        
FILEdestfile fopen(dest"wb");;
        
int entry_count 1;
        
int entry_skips 0;
        
int error_step 1;
        while (
ar_parse_entry(ar)) {
            
size_t size ar_entry_get_size(ar);
            while (
size 0) {
                
unsigned char buffer[1024];
                
size_t count size sizeof(buffer) ? size sizeof(buffer);
                if (!
ar_entry_uncompress(arbuffercount))
                    break;

                
fwrite(buffersizeof(char), countdestfile);
                
size -= count;
            }
            if (
size 0) {
                
fprintf(stderr"Warning: Failed to uncompress... skipping\n");
                
entry_skips++;
            }
        }
        
error_step entry_skips 1000 entry_skips 0;
        
fclose(destfile);
        
ar_close_archive(ar);
    }
    
ar_close(stream);
    return;


Hope this fixes the crash at least. Good luck! :)


All times are GMT -4. The time now is 12:13.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.