Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a checksum of the config file in memory #34146

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion lib/private/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class Config {
protected $configFileName;
/** @var bool */
protected $isReadOnly;
/** @var int */
protected $lastChecksum;

/**
* @param string $configDir Path to the config dir, needs to end with '/'
Expand Down Expand Up @@ -258,10 +260,23 @@ private function writeData() {
throw new HintException(sprintf('Configuration was not read or initialized correctly, not overwriting %s', $this->configFilePath));
}

// This creates a checksum of the config file in memory.
// The config file opcache code is only invalidated if the
// config file data has been changed therefore all the other
// code that depend on the the config file opcode will not
// be recompiled.
$data = var_export($this->cache, true);

Check failure

Code scanning / Psalm

TaintedHtml

Detected tainted HTML

Check failure

Code scanning / Psalm

TaintedHtml

Detected tainted HTML
$currentChecksum = crc32($data);

if ($this->getLastChecksum() == $currentChecksum)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will never be true, the checksum computed from file use the whole file content while the current one use only the data.

return;

$this->lastChecksum = $currentChecksum;

// Create a php file ...
$content = "<?php\n";
$content .= '$CONFIG = ';
$content .= var_export($this->cache, true);
$content .= $data;
$content .= ";\n";

touch($this->configFilePath);
Expand Down Expand Up @@ -304,4 +319,16 @@ private function checkReadOnly(): void {
'Unset "config_is_read_only" to allow changes to the config file.');
}
}

private function getLastChecksum(): int {
if ($this->lastChecksum == null) {
if (file_exists($this->configFilePath)) {
$data = file_get_contents($this->configFilePath);
$this->lastChecksum = crc32($data);
} else {
$this->lastChecksum = 0;
}
}
return $this->lastChecksum;
}
}