prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  [CKV_DOCKER_7] Erroneous failed check when --platform flag is used in multistage Dockerfile
  **Describe the issue**
  In the `CKV_DOCKER_7` check, when the `--platform` flag is used in a multistage Dockerfile, the check fails erroneously for images that have been created within the current Dockerfile and thus no version pegging should be required.
  
  **Examples**
  The Dockerfile below is green
  
  ```
  FROM golang:1.20-bullseye AS base
  
  FROM base AS build
  ```
  
  but as soon as a `--platform` flag is added, the check fails:
  
  ```
  FROM --platform=$BUILDPLATFORM golang:1.20-bullseye AS base
  
  FROM base AS build
  ```
  
  **Version (please complete the following information):**
   - Checkov Version 2.4.4
  
  </issue>
  <code>
  [start of checkov/dockerfile/checks/ReferenceLatestTag.py]
  1 from __future__ import annotations
  2 
  3 import re
  4 from typing import TYPE_CHECKING
  5 
  6 from checkov.common.models.enums import CheckCategories, CheckResult
  7 from checkov.dockerfile.base_dockerfile_check import BaseDockerfileCheck
  8 
  9 if TYPE_CHECKING:
  10     from dockerfile_parse.parser import _Instruction
  11 
  12 MULTI_STAGE_PATTERN = re.compile(r"(\S+)\s+as\s+(\S+)", re.IGNORECASE)
  13 
  14 
  15 class ReferenceLatestTag(BaseDockerfileCheck):
  16     def __init__(self) -> None:
  17         name = "Ensure the base image uses a non latest version tag"
  18         id = "CKV_DOCKER_7"
  19         supported_instructions = ("FROM",)
  20         categories = (CheckCategories.CONVENTION,)
  21         super().__init__(name=name, id=id, categories=categories, supported_instructions=supported_instructions)
  22 
  23     def scan_resource_conf(self, conf: list[_Instruction]) -> tuple[CheckResult, list[_Instruction] | None]:
  24         stages = []
  25 
  26         for content in conf:
  27             base_image = content["value"]
  28             if " as " in base_image.lower():
  29                 # do an initial lookup before using the regex
  30                 multi_stage = re.match(MULTI_STAGE_PATTERN, base_image)
  31                 if multi_stage:
  32                     base_image = multi_stage[1]
  33                     stages.append(multi_stage[2])
  34 
  35             if ":" not in base_image and base_image not in stages and base_image != "scratch":
  36                 return CheckResult.FAILED, [content]
  37             elif base_image.endswith(":latest"):
  38                 return CheckResult.FAILED, [content]
  39         return CheckResult.PASSED, [content]
  40 
  41 
  42 check = ReferenceLatestTag()
  43
  [end of checkov/dockerfile/checks/ReferenceLatestTag.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/checkov/dockerfile/checks/ReferenceLatestTag.py b/checkov/dockerfile/checks/ReferenceLatestTag.py
  --- a/checkov/dockerfile/checks/ReferenceLatestTag.py
  +++ b/checkov/dockerfile/checks/ReferenceLatestTag.py
  @@ -9,7 +9,7 @@
   if TYPE_CHECKING:
       from dockerfile_parse.parser import _Instruction
   
  -MULTI_STAGE_PATTERN = re.compile(r"(\S+)\s+as\s+(\S+)", re.IGNORECASE)
  +MULTI_STAGE_PATTERN = re.compile(r"(?:--platform=\S+\s+)?(\S+)\s+as\s+(\S+)", re.IGNORECASE)
   
   
   class ReferenceLatestTag(BaseDockerfileCheck):
  
verification_info: {"golden_diff": "diff --git a/checkov/dockerfile/checks/ReferenceLatestTag.py b/checkov/dockerfile/checks/ReferenceLatestTag.py\n--- a/checkov/dockerfile/checks/ReferenceLatestTag.py\n+++ b/checkov/dockerfile/checks/ReferenceLatestTag.py\n@@ -9,7 +9,7 @@\n if TYPE_CHECKING:\n     from dockerfile_parse.parser import _Instruction\n \n-MULTI_STAGE_PATTERN = re.compile(r\"(\\S+)\\s+as\\s+(\\S+)\", re.IGNORECASE)\n+MULTI_STAGE_PATTERN = re.compile(r\"(?:--platform=\\S+\\s+)?(\\S+)\\s+as\\s+(\\S+)\", re.IGNORECASE)\n \n \n class ReferenceLatestTag(BaseDockerfileCheck):\n", "issue": "[CKV_DOCKER_7] Erroneous failed check when --platform flag is used in multistage Dockerfile\n**Describe the issue**\r\nIn the `CKV_DOCKER_7` check, when the `--platform` flag is used in a multistage Dockerfile, the check fails erroneously for images that have been created within the current Dockerfile and thus no version pegging should be required.\r\n\r\n**Examples**\r\nThe Dockerfile below is green\r\n\r\n```\r\nFROM golang:1.20-bullseye AS base\r\n\r\nFROM base AS build\r\n```\r\n\r\nbut as soon as a `--platform` flag is added, the check fails:\r\n\r\n```\r\nFROM --platform=$BUILDPLATFORM golang:1.20-bullseye AS base\r\n\r\nFROM base AS build\r\n```\r\n\r\n**Version (please complete the following information):**\r\n - Checkov Version 2.4.4\n", "before_files": [{"content": "from __future__ import annotations\n\nimport re\nfrom typing import TYPE_CHECKING\n\nfrom checkov.common.models.enums import CheckCategories, CheckResult\nfrom checkov.dockerfile.base_dockerfile_check import BaseDockerfileCheck\n\nif TYPE_CHECKING:\n    from dockerfile_parse.parser import _Instruction\n\nMULTI_STAGE_PATTERN = re.compile(r\"(\\S+)\\s+as\\s+(\\S+)\", re.IGNORECASE)\n\n\nclass ReferenceLatestTag(BaseDockerfileCheck):\n    def __init__(self) -> None:\n        name = \"Ensure the base image uses a non latest version tag\"\n        id = \"CKV_DOCKER_7\"\n        supported_instructions = (\"FROM\",)\n        categories = (CheckCategories.CONVENTION,)\n        super().__init__(name=name, id=id, categories=categories, supported_instructions=supported_instructions)\n\n    def scan_resource_conf(self, conf: list[_Instruction]) -> tuple[CheckResult, list[_Instruction] | None]:\n        stages = []\n\n        for content in conf:\n            base_image = content[\"value\"]\n            if \" as \" in base_image.lower():\n                # do an initial lookup before using the regex\n                multi_stage = re.match(MULTI_STAGE_PATTERN, base_image)\n                if multi_stage:\n                    base_image = multi_stage[1]\n                    stages.append(multi_stage[2])\n\n            if \":\" not in base_image and base_image not in stages and base_image != \"scratch\":\n                return CheckResult.FAILED, [content]\n            elif base_image.endswith(\":latest\"):\n                return CheckResult.FAILED, [content]\n        return CheckResult.PASSED, [content]\n\n\ncheck = ReferenceLatestTag()\n", "path": "checkov/dockerfile/checks/ReferenceLatestTag.py"}]}