r97919 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97918‎ | r97919 | r97920 >
Date:14:14, 23 September 2011
Author:reedy
Status:resolved (Comments)
Tags:
Comment:
Mostly revert r97328

Swap substring to be done on smaller (more correct) values
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/GlobalFunctions.php
@@ -852,15 +852,15 @@
853853 $text = preg_replace( '/^/m', $prefix . ' ', $text );
854854
855855 // Limit to 64KB
856 - if ( strlen( $text ) > 65534 ) {
857 - $text = substr( $text, 0, 65534 );
 856+ if ( strlen( $text ) > 65506 ) {
 857+ $text = substr( $text, 0, 65505 );
858858 }
859859
860860 if ( substr( $text, -1 ) != "\n" ) {
861861 $text .= "\n";
862862 }
863 - } elseif ( strlen( $text ) > 65535 ) {
864 - $text = substr( $text, 0, 65535 );
 863+ } elseif ( strlen( $text ) > 65507 ) {
 864+ $text = substr( $text, 0, 65506 );
865865 }
866866
867867 $sock = socket_create( $domain, SOCK_DGRAM, SOL_UDP );
@@ -868,13 +868,7 @@
869869 return;
870870 }
871871
872 - $len = strlen( $text );
873 - $maxLen = socket_get_option( $sock, SOL_SOCKET, SO_SNDBUF );
874 -
875 - if ( $len > $maxLen ) {
876 - $len = $maxLen - 1;
877 - }
878 - socket_sendto( $sock, $text, $len, 0, $host, $port );
 872+ socket_sendto( $sock, $text, strlen( $text ), 0, $host, $port );
879873 socket_close( $sock );
880874 } else {
881875 wfSuppressWarnings();

Follow-up revisions

RevisionCommit summaryAuthorDate
r97941God. Damn. You. Php....reedy18:01, 23 September 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r97328Noticed in apache error logs (see below). If the length of the message is lon...reedy20:08, 16 September 2011

Comments

#Comment by Brion VIBBER (talk | contribs)   17:20, 23 September 2011

Is there a reason that you're cropping the message to N-1 bytes when checking if it's bigger than N bytes? This means a message with exactly N bytes will end up one byte longer than any longer message.

#Comment by Reedy (talk | contribs)   17:50, 23 September 2011

0 based indexing?

The first one is appending a newline, the target value is max 65507, so if it's longer than 65506 (66507 with newline), we cropping it from 0-65505 (which equals 65506), add a newlne, gives 65507

In the second case if it's longer than the target of 65507, we trim it from 0-65506 (65507) which is the target value

#Comment by Brion VIBBER (talk | contribs)   17:52, 23 September 2011

substr takes a starting point and a length, not a starting point and an ending point.

#Comment by Reedy (talk | contribs)   17:53, 23 September 2011

Bah

Status & tagging log