<commit_before><?php try {

  require_once(__DIR__ . "/init.php");

  if (list($fileId) = handle([REQUEST_PARAMETER], true)) {
    $file = \ICA\Files\getFile($fileId);
    if (!$file) throw new Exception("File not found");

    preg_match("/([^\/]+)\/([^\/]+)/", $file->mime, $matches);

    switch ($matches[1]) {
      case "image":
        // Check if request needs image resizing
        if ($_GET["width"] || $_GET["height"]) {
          $width = isset($_GET["width"]) ? intval($_GET["width"]) : 0;
          $height = isset($_GET["height"]) ? intval($_GET["height"]) : 0;

          $path = DIR_ROOT . "/cache/{$file->path}/{$width}x{$height}";
          // Resize the image if not already made available
          $imageFunctionPairs = [
            "jpeg" => ["imagecreatefromjpeg", "imagejpeg"]
          ];

          if (file_exists($path)) {
            respondFile($path, $file->mime);
          } elseif (array_key_exists($matches[2], $imageFunctionPairs)) {
            $src = $imageFunctionPairs[$matches[2]][0](DIR_ROOT . "/data/{$file->path}");

            list($imageWidth, $imageHeight) = getimagesize(DIR_ROOT . "/data/{$file->path}");
            if ($width <= 0 && $height > 0) {
              $width = $imageWidth * $height / $imageHeight;
            } elseif ($height <= 0 && $width > 0) {
              $height= $width * $imageHeight / $imageWidth;
            } elseif ($width <= 0 && $height <= 0) {
              $width = $imageWidth;
              $height = $imageHeight;
            }
            $dst = imagecreatetruecolor($width, $height);
            imagecopyresampled($dst, $src, 0, 0, 0, 0, $width, $height, $imageWidth, $imageHeight);
<commit_msg>Fix width and height query parameter validation<commit_after><?php try {

  require_once(__DIR__ . "/init.php");

  if (list($fileId) = handle([REQUEST_PARAMETER], true)) {
    $file = \ICA\Files\getFile($fileId);
    if (!$file) throw new Exception("File not found");

    preg_match("/([^\/]+)\/([^\/]+)/", $file->mime, $matches);

    switch ($matches[1]) {
      case "image":
        // Check if request needs image resizing
        if (isset($_GET["width"]) || isset($_GET["height"])) {
          $width = isset($_GET["width"]) ? intval($_GET["width"]) : 0;
          $height = isset($_GET["height"]) ? intval($_GET["height"]) : 0;

          $path = DIR_ROOT . "/cache/{$file->path}/{$width}x{$height}";
          // Resize the image if not already made available
          $imageFunctionPairs = [
            "jpeg" => ["imagecreatefromjpeg", "imagejpeg"]
          ];

          if (file_exists($path)) {
            respondFile($path, $file->mime);
          } elseif (array_key_exists($matches[2], $imageFunctionPairs)) {
            $src = $imageFunctionPairs[$matches[2]][0](DIR_ROOT . "/data/{$file->path}");

            list($imageWidth, $imageHeight) = getimagesize(DIR_ROOT . "/data/{$file->path}");
            if ($width <= 0 && $height > 0) {
              $width = $imageWidth * $height / $imageHeight;
            } elseif ($height <= 0 && $width > 0) {
              $height= $width * $imageHeight / $imageWidth;
            } elseif ($width <= 0 && $height <= 0) {
              $width = $imageWidth;
              $height = $imageHeight;
            }
            $dst = imagecreatetruecolor($width, $height);
            imagecopyresampled($dst, $src, 0, 0, 0, 0, $width, $height, $imageWidth, $imageHeight);

{'fraction_non_alphanumeric': 0.1927570093457944, 'fraction_numerical': 0.009345794392523364, 'mean_word_length': 2.387734915924827, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7088835', 'n_tokens_mistral': 1070, 'n_tokens_neox': 1042, 'n_words': 226}