wp/wp-includes/sodium_compat/src/File.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
--- a/wp/wp-includes/sodium_compat/src/File.php	Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-includes/sodium_compat/src/File.php	Tue Dec 15 13:49:49 2020 +0100
@@ -679,7 +679,11 @@
         }
 
         /* Security checks */
-        if (ParagonIE_Sodium_Core_Ed25519::check_S_lt_L(self::substr($sig, 32, 32))) {
+        if (
+            (ParagonIE_Sodium_Core_Ed25519::chrToInt($sig[63]) & 240)
+                &&
+            ParagonIE_Sodium_Core_Ed25519::check_S_lt_L(self::substr($sig, 32, 32))
+        ) {
             throw new SodiumException('S < L - Invalid signature');
         }
         if (ParagonIE_Sodium_Core_Ed25519::small_order($sig)) {
@@ -841,7 +845,7 @@
         if (!is_string($plaintext)) {
             throw new SodiumException('Could not read input file');
         }
-        $first32 = ftell($ifp);
+        $first32 = self::ftell($ifp);
 
         /** @var string $subkey */
         $subkey = ParagonIE_Sodium_Core_HSalsa20::hsalsa20($nonce, $key);
@@ -875,7 +879,7 @@
         );
 
         // Pre-write 16 blank bytes for the Poly1305 tag
-        $start = ftell($ofp);
+        $start = self::ftell($ofp);
         fwrite($ofp, str_repeat("\x00", 16));
 
         /** @var string $c */
@@ -926,7 +930,7 @@
             $block0 = null;
             $subkey = null;
         }
-        $end = ftell($ofp);
+        $end = self::ftell($ofp);
 
         /*
          * Write the Poly1305 authentication tag that provides integrity
@@ -1043,7 +1047,7 @@
         $mlen = 0
     ) {
         /** @var int $pos */
-        $pos = ftell($ifp);
+        $pos = self::ftell($ifp);
 
         /** @var int $iter */
         $iter = 1;
@@ -1106,7 +1110,7 @@
         }
 
         /** @var int $originalPosition */
-        $originalPosition = ftell($fp);
+        $originalPosition = self::ftell($fp);
 
         // Move file pointer to beginning of file
         fseek($fp, 0, SEEK_SET);
@@ -1314,7 +1318,7 @@
         if (!is_string($plaintext)) {
             throw new SodiumException('Could not read input file');
         }
-        $first32 = ftell($ifp);
+        $first32 = self::ftell($ifp);
 
         /** @var string $subkey */
         $subkey = ParagonIE_Sodium_Core32_HSalsa20::hsalsa20($nonce, $key);
@@ -1348,7 +1352,7 @@
         );
 
         // Pre-write 16 blank bytes for the Poly1305 tag
-        $start = ftell($ofp);
+        $start = self::ftell($ofp);
         fwrite($ofp, str_repeat("\x00", 16));
 
         /** @var string $c */
@@ -1399,7 +1403,7 @@
             $block0 = null;
             $subkey = null;
         }
-        $end = ftell($ofp);
+        $end = self::ftell($ofp);
 
         /*
          * Write the Poly1305 authentication tag that provides integrity
@@ -1515,7 +1519,7 @@
         $mlen = 0
     ) {
         /** @var int $pos */
-        $pos = ftell($ifp);
+        $pos = self::ftell($ifp);
 
         /** @var int $iter */
         $iter = 1;
@@ -1540,4 +1544,18 @@
         fseek($ifp, $pos, SEEK_SET);
         return $res;
     }
+
+    /**
+     * @param resource $resource
+     * @return int
+     * @throws SodiumException
+     */
+    private static function ftell($resource)
+    {
+        $return = ftell($resource);
+        if (!is_int($return)) {
+            throw new SodiumException('ftell() returned false');
+        }
+        return (int) $return;
+    }
 }