Repository: xbmc/xbmc
File: xbmc/video/VideoInfoScanner.cpp (C++)

Code before:
      return;

    CFileItemList availableArtFiles;
    CDirectory::GetDirectory(path, availableArtFiles,
        CServiceBroker::GetFileExtensionProvider().GetPictureExtensions(),
        DIR_FLAG_NO_FILE_DIRS | DIR_FLAG_READ_CACHE | DIR_FLAG_NO_FILE_INFO);

    std::string baseFilename = URIUtils::GetFileName(itemPath);
    if (!baseFilename.empty())
    {
      URIUtils::RemoveExtension(baseFilename);
      baseFilename.append("-");
    }

    bool caseSensitive{CServiceBroker::GetSettingsComponent()
                           ->GetAdvancedSettings()
                           ->m_bCaseSensitiveLocalArtMatch};

    for (const auto& artFile : availableArtFiles)
    {
      std::string candidate = URIUtils::GetFileName(artFile->GetPath());

      bool matchesFilename;
      if (caseSensitive)
        matchesFilename = !baseFilename.empty() && StringUtils::StartsWith(candidate, baseFilename);
      else
        matchesFilename =
            !baseFilename.empty() && StringUtils::StartsWithNoCase(candidate, baseFilename);

      if (!baseFilename.empty() && !matchesFilename)
        continue;

      if (matchesFilename)
        candidate.erase(0, baseFilename.length());
      URIUtils::RemoveExtension(candidate);
      StringUtils::ToLower(candidate);

      // move 'folder' to thumb / poster / banner based on aspect ratio
      // if such artwork doesn't already exist
      if (!matchesFilename && StringUtils::EqualsNoCase(candidate, "folder") &&
        !CVideoThumbLoader::IsArtTypeInWhitelist("folder", wantedArtTypes, exactName))
      {
        // cache the image to determine sizing
        CTextureDetails details;
        if (CServiceBroker::GetTextureCache()->CacheImage(artFile->GetPath(), details))
        {
          candidate = GetArtTypeFromSize(details.width, details.height);
          if (itemArt.find(candidate) != itemArt.end())
            continue;
        }
      }

Review comment (security):
Maybe change this into a single statement?
```suggestion

      const bool matchesFilename = !baseFilename.empty() && caseSensitive
                                       ? StringUtils::StartsWith(candidate, baseFilename)
                                       : StringUtils::StartsWithNoCase(candidate, baseFilename);

```

Code after:
      return;

    CFileItemList availableArtFiles;
    CDirectory::GetDirectory(path, availableArtFiles,
        CServiceBroker::GetFileExtensionProvider().GetPictureExtensions(),
        DIR_FLAG_NO_FILE_DIRS | DIR_FLAG_READ_CACHE | DIR_FLAG_NO_FILE_INFO);

    std::string baseFilename = URIUtils::GetFileName(itemPath);
    if (!baseFilename.empty())
    {
      URIUtils::RemoveExtension(baseFilename);
      baseFilename.append("-");
    }

    const bool caseSensitive{CServiceBroker::GetSettingsComponent()
                                 ->GetAdvancedSettings()
                                 ->m_caseSensitiveLocalArtMatch};

    for (const auto& artFile : availableArtFiles)
    {
      std::string candidate{URIUtils::GetFileName(artFile->GetPath())};
      const bool matchesFilename{!baseFilename.empty() &&
                                 (caseSensitive
                                      ? StringUtils::StartsWith(candidate, baseFilename)
                                      : StringUtils::StartsWithNoCase(candidate, baseFilename))};

      if (!baseFilename.empty() && !matchesFilename)
        continue;

      if (matchesFilename)
        candidate.erase(0, baseFilename.length());
      URIUtils::RemoveExtension(candidate);
      StringUtils::ToLower(candidate);

      // move 'folder' to thumb / poster / banner based on aspect ratio
      // if such artwork doesn't already exist
      if (!matchesFilename && StringUtils::EqualsNoCase(candidate, "folder") &&
        !CVideoThumbLoader::IsArtTypeInWhitelist("folder", wantedArtTypes, exactName))
      {
        // cache the image to determine sizing
        CTextureDetails details;
        if (CServiceBroker::GetTextureCache()->CacheImage(artFile->GetPath(), details))
        {
          candidate = GetArtTypeFromSize(details.width, details.height);
          if (itemArt.find(candidate) != itemArt.end())
            continue;
        }
      }

      if ((addAll && CVideoThumbLoader::IsValidArtType(candidate)) ||
        CVideoThumbLoader::IsArtTypeInWhitelist(candidate, wantedArtTypes, exactName))