A platform for community discussion. Free, open, simple.
FIX: Limit post read time to the max integer value (#12126)
Osama Sayegh69017298e839
diff --git a/app/models/post_timing.rb b/app/models/post_timing.rbindex 8251d429074..7fbe31b8f81 100644--- a/app/models/post_timing.rb+++ b/app/models/post_timing.rb@@ -165,7 +165,7 @@ class PostTiming < ActiveRecord::Baseif join_table.length > 0sql = <<~SQLUPDATE post_timings t- SET msecs = t.msecs + x.msecs+ SET msecs = LEAST(t.msecs::bigint + x.msecs, 2^31 - 1)FROM (#{join_table.join(" UNION ALL ")}) xWHERE x.topic_id = t.topic_id ANDx.post_number = t.post_number ANDdiff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rbindex dbeb2dc91b2..4714d4d44b8 100644--- a/spec/requests/topics_controller_spec.rb+++ b/spec/requests/topics_controller_spec.rb@@ -3057,6 +3057,29 @@ RSpec.describe TopicsController doexpect(post_timing.user).to eq(user)expect(post_timing.msecs).to eq(2)end++ it 'caps post read time at the max integer value (2^31 - 1)' do+ PostTiming.create!(+ topic_id: post_1.topic.id,+ post_number: post_1.post_number,+ user_id: user.id,+ msecs: 2**31 - 10+ )+ sign_in(user)++ post "/topics/timings.json", params: {+ topic_id: topic.id,+ topic_time: 5,+ timings: { post_1.post_number => 100 }+ }++ expect(response.status).to eq(200)+ post_timing = PostTiming.first++ expect(post_timing.topic).to eq(topic)+ expect(post_timing.user).to eq(user)+ expect(post_timing.msecs).to eq(2**31 - 1)+ endenddescribe '#timer' do