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

Unbounded stack buffers in CS:GO closed-caption parser (SplitCommand) overflow via crafted caption file, enabling remote code execution.

- Payout: $7,500
- Severity: critical
- Program: Valve
- Found by: gamer7112
- Disclosed: 2021-05-05
- Write-up quality: 7/10
- Original: https://hackerone.com/reports/463286
- Library page: https://bugbountylibrary.com/r/h1%3A463286
- Tags: area:os domain:desktop impact:rce kind:bounty platform:hackerone sev:critical tech:windows technique:source-review vuln:memory-corruption vuln:rce

**Target:** CS:GO / Source engine closed caption parser (CHudCloseCaption::SplitCommand)
**Root cause:** SplitCommand copies caption tokens into fixed 256-wchar stack buffers cmd and args without length checks, overflowing when a token exceeds 256 wide chars.
**Steps:**
1. Craft a closed captions file containing a token like `<` followed by >256 wide chars before a `:`/`>`/whitespace, and similarly for the args portion.
2. Load the file so CHudCloseCaption::GetNoRepeatValue iterates captions and calls SplitCommand.
3. SplitCommand's `*out++ = *in++` loops write past cmd[256]/args[256] on the stack.
4. Control overflow to overwrite return address and achieve code execution.
**How found:** Code review of GetNoRepeatValue/SplitCommand revealed fixed-size stack buffers written in unbounded while loops with no boundary checks.
**Exploitation:** Attacker supplies a malicious closed-caption file; parser overflows stack buffers cmd/args in SplitCommand, allowing control of return address for RCE in the game process.
**Insight:** Caption/subtitle parsers that tokenize into fixed stack buffers are a recurring RCE surface in game engines; audit any `*out++ = *in++` loop lacking a length guard.

## Proof of concept (copied exactly from the original report)

**Vulnerable SplitCommand overflow code**

```
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;
	}
```

**GetNoRepeatValue calling vulnerable SplitCommand**

```
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;
}
```

