Skip to content

Commit 2abd4c7

Browse files
committed
Fix postgres big decimal test, it shows up when prepared statement is disabled and relates to CVE-2022-44566 fix
1 parent 8f167b4 commit 2abd4c7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/db/postgresql/simple_test.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,27 @@ def test_custom_select_date
5858
assert_equal my_date, sample_date
5959
end
6060

61+
# @override
62+
def test_big_decimal
63+
test_value = BigDecimal('9876543210_9876543210_9876543210.0')
64+
65+
conn = DbType.connection
66+
67+
if conn.prepared_statements?
68+
db_type = DbType.create!(big_decimal: test_value)
69+
db_type = DbType.find(db_type.id)
70+
assert_kind_of Integer, db_type.big_decimal
71+
assert_equal test_value, db_type.big_decimal
72+
else
73+
# it seems the patch applies when prepared statements is disabled
74+
# https://discuss.rubyonrails.org/t/cve-2022-44566-possible-denial-of-service-vulnerability-in-activerecords-postgresql-adapter/82119
75+
# https://github.com/rails/rails/commit/4f44aa9d514e701ada92b5cf08beccf566eeaebf
76+
assert_raise ActiveRecord::ConnectionAdapters::PostgreSQL::Quoting::IntegerOutOf64BitRange do
77+
DbType.create!(big_decimal: test_value)
78+
end
79+
end
80+
end
81+
6182
def test_encoding
6283
assert_not_nil connection.encoding
6384
end

0 commit comments

Comments
 (0)