Closed (fixed)
Project:
Drupal core
Version:
4.6.x-dev
Component:
comment.module
Priority:
Minor
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
21 Jan 2003 at 20:15 UTC
Updated:
1 Jun 2007 at 18:29 UTC
I cannot for the life of me figure out how the moderation matrix affects the score of comments when used by different users. See http://www.drupal.org/node.php?id=1046 for more details.
I'm guessing this functionality is not widely used (and hence not tested)? Either that, or I am completely ignorant of how to use it properly.
![]()
Comments
Comment #1
matt-1 commentedI may have figured out why my math is bad...it looks like the score is an average of the users votes. However, there is a race condition. Here are lines 1312 to 1328 from modules/comment.module:
Notice that the math is done outside of the database before the update. As far as I can tell, the rows being updated have not yet been locked (I'm not even sure if there are any transactional boundaries anywhere in the whole application). If two users moderate at the same time, one of them is at risk of not having his moderation "take" (i.e., it looks like it will appear as if that comment was never moderated by one of the users).
---
If possible the calculation should be made in the SQL statement (or at least the row should be locked within a transaction boundary before reading the old score). Here's an example using PEAR_DB (one would have to add another column
num_usersto the table if one still wanted to calculate averages):I would also leave score as a float (rather than an integer) to reflect its nature as an average rather than an aggregate. Without it being a float, even the current method of calculating scores is wrong (or at least really lossy after two votes).
You'll probably note that even with my proposed SQL statement, this doesn't help out in the case where a single malicious user makes several concurrent attempts to moderate the same comment in efforts to gain more influence. Now that I think about it, my half-assed proposal seems worse...one runs the risk of counting votes without properly attributing them to anyone, where at least in the original code, the worst that can happen is that the net effect of someone's moderation is zero (i.e., they have to do it again). I don't think there's there's a way around that without transactional row-locking given the current data model, since it would be impossible (or at least really really difficult) to do the parsing and evaluation of the
usersfield inside aWHEREclause.Of course, all this makes me wonder how many other non thread-safe things there are in the application....
Comment #2
(not verified) commentedComment #3
moshe weitzman commentedchanging title
Comment #4
moshe weitzman commentedComment #5
Paul Natsuo Kishimoto commentedMoshe, does this even exist anymore? If not, I vote to close.
Also, it looks like bugs can no longer be against x.y.z. Woohoo!
Comment #6
forngren commentedDead by know.