Skip to content
Memory corruption Disclosed report Advanced

Specially Crafted Closed Captions File can lead to Remote Code Execution in CS:GO and other Source Games

A specially crafted closed captions file causes a buffer overflow in the game's caption parser because the functions that split caption commands into fixed-size stack buffers do not check length. An attacker could use this to execute arbitrary code on a victim's machine.

gamer7112 Follow

Originally disclosed on HackerOne

Bounty$7,500 Critical 9.6 View original
  • Triaged in 15 months
  • Fixed in 2.4 years
  • Paid in 2.4 years
  • Disclosed after 2.4 years

Summary by the program

With a specially crafted closed captions file, the parser calls CHudCloseCaption::GetNoRepeatValue which in turn calls CHudCloseCaption::SplitCommand which has no boundary checks allowing the on stack variables cmd and args to be overflowed which in turn allows Remote Code Execution.

Summary by the researcher

Buffer overflow via the closed captioning system in the function CHudCloseCaption::SplitCommand which can be reached via the function CHudCloseCaption::GetNoRepeatValue

C++
bool CHudCloseCaption::GetNoRepeatValue( const wchar_t *caption, float &retval )
{
	retval = 0.0f;
	const wchar_t *curpos = caption;
	
	for ( ; curpos && *curpos != L'\0'; ++curpos )
	{
		wchar_t cmd[ 256 ];
		wchar_t args[ 256 ];

		if ( SplitCommand( &curpos, cmd, args ) )//Vulnerable call
		{
			if ( !wcscmp( cmd, L"norepeat" ) )
			{
				retval = (float)wcstod( args, NULL );
				return true;
			}
			continue;
		}
	}
	return false;
}

bool CHudCloseCaption::SplitCommand( wchar_t const **ppIn, wchar_t *cmd, wchar_t *args ) const
{
	const wchar_t *in = *ppIn;
	const wchar_t *oldin = in;

	if ( in[0] != L'<' )
	{
		*ppIn += ( oldin - in );
		return false;
	}

	args[ 0 ] = 0;
	cmd[ 0 ]= 0;
	wchar_t *out = cmd;
	in++;
	while ( *in != L'\0' && *in != L':' && *in != L'>' && !V_isspace( *in ) )
	{
		*out++ = *in++;//Vulnerable overflow
	}
	*out = L'\0';

	if ( *in != L':' )
	{
		*ppIn += ( in - oldin );
		return true;
	}

	in++;
	out = args;
	while ( *in != L'\0' && *in != L'>' )
	{
		*out++ = *in++;//Vulnerable overflow
	}
	*out = L'\0';

	//if ( *in == L'>' )
	//	in++;

	*ppIn += ( in - oldin );
	return true;
}

The original report as published on HackerOne, by gamer7112. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The caption parsing functions copy characters into fixed-size stack buffers without checking the length of the input, leading to a stack buffer overflow.

Impact

An attacker could achieve remote code execution on a victim's machine by supplying a malicious closed captions file.

What the attacker needed

Victim loads a malicious captions file

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A closed captions file is a text file that tells the game what subtitles to show. The game reads this file and copies parts of it into small, fixed-size boxes in memory without checking if the text is too long. If the text is longer than the box, it spills over into nearby memory, and an attacker can use that spill to run their own code.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by gamer7112

View all

9 more disclosed reports, best first.

More from Valve

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.