Ticket #3247: mc-3247-directory-size-frame-limit-PoC.patch

File mc-3247-directory-size-frame-limit-PoC.patch, 3.5 KB (added by egmont, 5 years ago)

Proof of concept

  • lib/util.c

    diff --git a/lib/util.c b/lib/util.c
    index ceace41..556f370 100644
    a b mc_replace_error (GError ** dest, int code, const char *format, ...) 
    14511451} 
    14521452 
    14531453/* --------------------------------------------------------------------------------------------- */ 
     1454 
     1455/** 
     1456 * Returns if the given duration has elapsed since the given timestamp, 
     1457 * and if it has then updates the timestamp. 
     1458 * Returns TRUE if clock skew detected. 
     1459 * 
     1460 * @param tv the last timestamp, updated if the given time elapsed 
     1461 * @param duration amount of time in seconds 
     1462 */ 
     1463gboolean 
     1464mc_time_elapsed (double *timestamp, double delay) 
     1465{ 
     1466    struct timeval tv_now; 
     1467    double now; 
     1468 
     1469    if (gettimeofday(&tv_now, NULL) != 0) 
     1470        return TRUE; 
     1471    now = tv_now.tv_sec + tv_now.tv_usec / 1000000.0; 
     1472 
     1473    if (now >= *timestamp && now < *timestamp + delay) 
     1474        return FALSE; 
     1475 
     1476    *timestamp = now; 
     1477    return TRUE; 
     1478} 
     1479 
     1480/* --------------------------------------------------------------------------------------------- */ 
  • lib/util.h

    diff --git a/lib/util.h b/lib/util.h
    index 26ba190..5f29ff5 100644
    a b char *mc_build_filenamev (const char *first_element, va_list args); 
    207207void mc_propagate_error (GError ** dest, int code, const char *format, ...); 
    208208void mc_replace_error (GError ** dest, int code, const char *format, ...); 
    209209 
     210gboolean mc_time_elapsed (double *timestamp, double delay); 
     211 
    210212/*** inline functions **************************************************/ 
    211213 
    212214static inline gboolean 
  • lib/widget/wtools.c

    diff --git a/lib/widget/wtools.c b/lib/widget/wtools.c
    index 058db93..efab61e 100644
    a b status_msg_init (status_msg_t * sm, const char *title, double delay, status_msg_ 
    575575{ 
    576576    sm->dlg = dlg_create (TRUE, 0, 0, 7, min (max (40, COLS / 2), COLS), dialog_colors, 
    577577                          NULL, NULL, NULL, title, DLG_CENTER); 
    578     sm->delay = delay * G_USEC_PER_SEC; 
     578    sm->delay = status_msg_delay_threshold + 1;  // delay * G_USEC_PER_SEC; 
    579579    sm->block = FALSE; 
    580580 
    581581    sm->init = init_cb; 
  • src/filemanager/file.c

    diff --git a/src/filemanager/file.c b/src/filemanager/file.c
    index caf375b..f8cdf29 100644
    a b do_compute_dir_size (const vfs_path_t * dirname_vpath, dirsize_status_msg_t * ds 
    529529    DIR *dir; 
    530530    struct dirent *dirent; 
    531531    FileProgressStatus ret = FILE_CONT; 
     532    static double timestamp = 0; 
    532533 
    533534    if (!compute_symlinks) 
    534535    { 
    do_compute_dir_size (const vfs_path_t * dirname_vpath, dirsize_status_msg_t * ds 
    568569                ret = 
    569570                    do_compute_dir_size (tmp_vpath, dsm, dir_count, ret_marked, ret_total, 
    570571                                         compute_symlinks); 
    571                 if (ret == FILE_CONT && sm->update != NULL) 
     572                if (ret == FILE_CONT && sm->update != NULL && mc_time_elapsed(&timestamp, 0.04 /* 25 FPS */)) 
    572573                { 
    573574                    dsm->dirname_vpath = tmp_vpath; 
    574575                    dsm->dir_count = *dir_count; 
    do_compute_dir_size (const vfs_path_t * dirname_vpath, dirsize_status_msg_t * ds 
    582583                *ret_total += (uintmax_t) s.st_size; 
    583584 
    584585                update_ui_count++; 
    585                 if ((update_ui_count & 31) == 0) 
     586                if ((update_ui_count & 31) == 0 && mc_time_elapsed(&timestamp, 0.04 /* 25 FPS */)) 
    586587                { 
    587588                    if (sm->update == NULL) 
    588589                        ret = FILE_CONT;