Miggo Logo

CVE-2021-29542:
Heap buffer overflow in `StringNGrams`

2.5

CVSS Score

Basic Information

EPSS Score
-
Published
5/21/2021
Updated
10/31/2024
KEV Status
No
Technology
TechnologyPython

Technical Details

CVSS Vector
CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:N/A:L
Package NameEcosystemVulnerable VersionsFirst Patched Version
tensorflowpip< 2.1.42.1.4
tensorflowpip>= 2.2.0, < 2.2.32.2.3
tensorflowpip>= 2.3.0, < 2.3.32.3.3
tensorflowpip>= 2.4.0, < 2.4.22.4.2
tensorflow-cpupip< 2.1.42.1.4
tensorflow-cpupip>= 2.2.0, < 2.2.32.2.3
tensorflow-cpupip>= 2.3.0, < 2.3.32.3.3
tensorflow-cpupip>= 2.4.0, < 2.4.22.4.2
tensorflow-gpupip< 2.1.42.1.4
tensorflow-gpupip>= 2.2.0, < 2.2.32.2.3
tensorflow-gpupip>= 2.3.0, < 2.3.32.3.3
tensorflow-gpupip>= 2.4.0, < 2.4.22.4.2

Vulnerability Intelligence
Miggo AIMiggo AI

Miggo AIRoot Cause Analysis

The vulnerability occurs in the ngram construction loop where token count validation is missing. The code calculates 'num_tokens = ngram_width - (left_padding + right_padding)' but proceeds to access 'data[data_start_index + num_tokens - 1]' without checking if 'num_tokens > 0'. When padding requirements force 'num_tokens=0', this becomes an invalid memory access. The patch explicitly adds a 'num_tokens > 0' guard around this operation, confirming this code path as the root cause.

Vulnerable functions

Only Mi**o us*rs **n s** t*is s**tion

WAF Protection Rules

WAF Rule

### Imp**t *n *tt**k*r **n **us* * ***p *u***r ov*r*low *y p*ssin* *r**t** inputs to `t*.r*w_ops.Strin*N*r*ms`: ```pyt*on import t*nsor*low *s t* s*p*r*tor = *'\x**\x**' n*r*m_wi*t*s = [*, *, **] l**t_p** = *'\x**\x**\x**\x**\x**' ri**t_p** = *

Reasoning

T** vuln*r**ility o**urs in t** n*r*m *onstru*tion loop w**r* tok*n *ount v*li**tion is missin*. T** *o** **l*ul*t*s 'num_tok*ns = n*r*m_wi*t* - (l**t_p***in* + ri**t_p***in*)' *ut pro****s to ****ss '**t*[**t*_st*rt_in**x + num_tok*ns - *]' wit*out