Certain path aliases cause MySQL errors. These aliases begin with a digit, followed by an "e" followed by another digit. EXAMPLE "1e309"

To Reproduce

  1. Create a piece of content with a path alias of "1e309"
  2. Download and enable Print module
  3. In the configuration page (/admin/settings/print) check the box labeled "Use URL alias instead of node ID"
  4. Visit the page with the alias of "1e309" and click the "Printer-friendly version" link at the bottom
  5. Note the error message reading something along the lines of user warning: Unknown column 'INF' in 'where clause' query: SELECT n.nid, n.type, n.language, n.uid, n.status, n.created, n.changed, n.comment, n.promote, n.moderate, n.sticky, n.tnid, n.translate, r.vid, r.uid AS revision_uid, r.title, r.body, r.teaser, r.log, r.timestamp AS revision_timestamp, r.format, u.name, u.picture, u.data FROM node n INNER JOIN users u ON u.uid = n.uid INNER JOIN node_revisions r ON r.vid = n.vid WHERE n.nid = INF in /modules/node/node.module on line 755.
  6. Note: this is on a 32bit linux server, on a 64bit OS, the number at which the error occurs may be larger.

The Reason
Certain path aliases can be registered as numbers. These aliases begin with a digit, followed by an "e" followed by another digit. EXAMPLE "1e309"
This is scientific notation and would be the same as 1 * 10^309
Specifically "1e309" is mentioned here because it causes an error while "1e308" does not. The reason for this is spelled out on the PHP integer and float pages:
http://www.php.net/manual/en/language.types.integer.php
http://www.php.net/manual/en/language.types.float.php
When an integer exceeds it's upper limit, it is automatically cast as a float in PHP and when a float exceeds its bounds it is cast as "INF" aka infinity.
This can be seen in the MySQL error right near the end... WHERE n.nid = INF

The Fix
To counteract this we need the is_numeric tests in print module to also check if the number is finite via the is_finite function.

CommentFileSizeAuthor
#1 path-aliases-mysql-errors-1196588-1.patch4.63 KBlliss
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lliss’s picture

This patch seems to solve the issue. It may be a little overkill because I've just added the check everywhere that is_numeric is called but I figure it can't really hurt.

jcnventura’s picture

Status: Active » Fixed

For this particular problem, the solution is to use ctype_digit() since is_finite would still return true to "1.2345", and I only want to accept integers.

I've replaced all calls to is_numeric() by ctype_digit(), and committed it to git.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.