--- ad_flash.module	2009-06-09 12:07:33.000000000 +1000
+++ ad_flash.module.patched	2009-06-09 11:22:21.000000000 +1000
@@ -364,30 +364,50 @@
 /**
  * Validate that the size of the uploaded flash is within the defined limits.
  */
-function ad_flash_validate_size($file, $gid) {
+function ad_flash_validate_size($file, $nid) {
   $size = NULL;
   $error = FALSE;
+  $edit = isset($_POST['edit']) ? $_POST['edit'] : array();
   if (is_object($file)) {
-  	if (strstr(strtolower($file->filename), '.flv')) return (object) array('width' => 0, 'height' => 0);
-	
-    $format = ad_flash_format_load($gid);
+    // TODO: Detect if new terms have been set, and if so validate against
+    // them, not the old ones.  See what's in $edit['taxonomy'].
+    $node = node_load($nid);
+    $terms = module_invoke('taxonomy', 'node_get_terms', $node);
+    if (count($terms) == 0) {
+      // We need at least a single (NULL) term to be ensure we still get the
+      // default flash size.
+      $terms[] = NULL;
+    }
+    foreach ($terms as $tid => $term) {
     list($size->width, $size->height) = getimagesize($file->filepath);
+      $size->bytes = strlen(join('', file($file->filepath)));
+      if ($format = ad_flash_format_load($tid)) {
     if ($size->width < $format->min_width) {
-      drupal_set_message(t('The flash %name is only %current pixels wide, which is less than the minimum of %minimum pixels allowed in the selected ad group.', array('%name' => $file->filename, '%current' => $size->width, '%minimum' => $format->min_width)), 'error');
+          drupal_set_message(t('The flash %name is only %current pixels wide, which is less than the minimum of %minimum pixels allowed in the %group ad group.', array('%name' => $file->filename, '%current' => $size->width, '%minimum' => $format->min_width, '%group' => isset($term->name) ? $term->name : t('default'))), 'error');
       $error = TRUE;
     }
     else if ($format->max_width && ($size->width > $format->max_width)) {
-      drupal_set_message(t('The flash %name is %current pixels wide, which is more than the maximum of %maximum pixels allowed in the selected ad group.', array('%name' => $file->filename, '%current' => $size->width, '%maximum' => $format->max_width)), 'error');
+          drupal_set_message(t('The flash %name is %current pixels wide, which is more than the maximum of %maximum pixels allowed in the %group ad group.', array('%name' => $file->filename, '%current' => $size->width, '%maximum' => $format->max_width, '%group' => isset($term->name) ? $term->name : t('default'))), 'error');
       $error = TRUE;
     }
     if ($size->height < $format->min_height) {
-      drupal_set_message(t('The flash %name is only %current pixels high, which is less than the minimum of %minimum pixels allowed in the selected ad group.', array('%name' => $file->filename, '%current' => $size->height, '%minimum' => $format->min_height)), 'error');
+          drupal_set_message(t('The flash %name is only %current pixels high, which is less than the minimum of %minimum pixels allowed in the %group ad group.', array('%name' => $file->filename, '%current' => $size->height, '%minimum' => $format->min_height, '%group' => isset($term->name) ? $term->name : t('default'))), 'error');
       $error = TRUE;
     }
     else if ($format->max_height && $size->height > $format->max_height) {
-      drupal_set_message(t('The flash %name is %current pixels high, which is more than the maximum of %maximum pixels allowed in the selected ad group.', array('%name' => $file->filename, '%current' => $size->height, '%maximum' => $format->max_height)), 'error');
+          drupal_set_message(t('The flash %name is %current pixels high, which is more than the maximum of %maximum pixels allowed in the %group ad group.', array('%name' => $file->filename, '%current' => $size->height, '%maximum' => $format->max_height, '%group' => isset($term->name) ? $term->name : t('default'))), 'error');
       $error = TRUE;
     }
+        if ($format->max_size && $size->bytes > $format->max_size) {
+          drupal_set_message(t('The flash %name is %current bytes in size, which is more than the maximum of %maximum bytes allowed in the %group ad group.', array('%name' => $file->filename, '%current' => $size->bytes, '%maximum' => $format->max_size, '%group' => isset($term->name) ? $term->name : t('default'))), 'error');
+          $error = TRUE;
+        }
+      }
+    }
+  }
+  else {
+    $error = TRUE;
+    drupal_set_message('Please report error: $file is not an object, bug #146147.');
   }
   if ($error) {
     return FALSE;
@@ -411,7 +431,7 @@
     foreach ($node->files as $file) {
       if (is_array($file)) {
         if ($file['list'] && file_exists($file['filepath'])) {
-          $flash = ad_flash_validate_size((object)$file, $node->gid);
+          $flash = ad_flash_validate_size((object)$file, $node->nid);
           if ($flash !== FALSE) {
             $flash->fid = $file['fid'];
 						$flash->type = strtolower(pathinfo($file['filepath'], PATHINFO_EXTENSION));
@@ -421,7 +441,7 @@
       }
       else {
         if ($file->list && file_exists($file->filepath)) {
-          $flash = ad_flash_validate_size($file, $node->gid);
+          $flash = ad_flash_validate_size($file, $node->nid);
           if ($flash !== FALSE) {
             $flash->fid = $file->fid;
 						$flash->type = strtolower(pathinfo($file->filepath, PATHINFO_EXTENSION));
@@ -464,7 +484,7 @@
         list($flash->width, $flash->height) = getimagesize($file->filepath);
         $flash->path = file_create_url($file->filepath);
         //$path .= theme('ad_flash_render', null, $flash);
-        $flash = ad_flash_validate_size($file, $node->gid);
+        $flash = ad_flash_validate_size($file, $node->nid);
         if ($flash === FALSE) {
           $path .= t('(invalid flash file)'). '<br />';
         }
