An integer overflow occurs when the answer to an arithmetic operation exceeds the maximum size of the integer type used to store it. The resulting value will appear to have wrapped around the maximum value and started again at the minimum value. This would look like a clock that represents 13:00 by pointing at 1:00. An attacker can use an integer overflow during a buffer length calculation, which results in the allocated buffer being too small to hold the data copied into it, thus causing a buffer overflow.
Unless checked, the resulting number can exceed the expected range.
engrampa/src/engrampa-1.18.1/src/fr-command-rar.c
The highlighted line of code below is the trigger point of this particular Alpine 3.6 integer weakness.
static time_t
mktime_from_string (const char *date_s,
const char *time_s)
{
struct tm tm = {0, };
char **fields;
tm.tm_isdst = -1;
/* date */
fields = g_strsplit (date_s, "-", 3);
if (fields[0] != NULL) {
if (date_newstyle)
tm.tm_year = atoi (fields[0]) - 1900;
else
tm.tm_mday = atoi (fields[0]);
if (fields[1] != NULL) {
tm.tm_mon = atoi (fields[1]) - 1;
if (fields[2] != NULL) {
if (date_newstyle)
tm.tm_mday = atoi (fields[2]);
else
tm.tm_year = 100 + atoi (fields[2]);
}
}
}
g_strfreev (fields);
/* time */
fields = g_strsplit (time_s, ":", 2);
if (fields[0] != NULL) {
tm.tm_hour = atoi (fields[0]);
if (fields[1] != NULL)
tm.tm_min = atoi (fields[1]);
}
g_strfreev (fields);
return mktime (&tm);
}
static gboolean
attribute_field_with_space (char *line)
{
/* sometimes when the archive is encrypted the attributes field is
* like this: "* ..A...."
* */
return ((line[0] != ' ') && (line[1] == ' '));