Skip to content

[3.0] Improves file integrity checks in installer and upgrader - #9679

Merged
Sesquipedalian merged 6 commits into
SimpleMachines:release-3.0from
Sesquipedalian:3.0/maint_manifest
Sep 13, 2026
Merged

Sesquipedalian merged 6 commits into
SimpleMachines:release-3.0from
Sesquipedalian:3.0/maint_manifest

Conversation

@Sesquipedalian

@Sesquipedalian Sesquipedalian commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

Until now, the installer and upgrader have only checked for the existence of certain files as their way of verifying that the package was uploaded successfully. But that is not very reliable.

This PR adds code to generate a complete manifest of all of SMF's files, which is stored in ./Sources/Maintenance/manifest.php. Then the installer and upgrader check the manifest to make sure all the required files are present.

Structure of manifest.php

The content of manifest.php looks like this:

return [
	'3.0' => [
		'attachments/.htaccess' => '66670ce0434ec8b6aec1042599cc3b20',
		'attachments/index.php' => '5af5d3f12a31e6e2b6e24e21865a2aa8',
		'avatars/blank.png' => true,
		'avatars/default.png' => true,
		'avatars/index.php' => '5af5d3f12a31e6e2b6e24e21865a2aa8',
		'cron.php' => 'deee205f26ed182ae2efc45d0d0215e4',
		// ...
	],
	'2.1' => [
		'Sources/Db/Schema/v2_1/AdminInfoFiles.php' => '62aba404ba5fa78f159e637da928a0e4',
 		// ...
	],
];

At the top level, the array keys are version numbers and the values are lists of files.

Within each version's list of files, each key is the relative path of a file that must exist, and each value is either a checksum or else a boolean true.

The true value means that the file (or directory, as the case may be) must exist, but that it is allowed to have arbitrary content. The reason to use true for a file is to ensure that the installer and upgrader won't choke if, for example, the admin has replaced the default smiley images or customized the content of agreement.txt, etc. The other situation where true is used is when we want to check for the existence of a directory inside ./vendor. In that situation, we don't control the content of the directory, so we just check that the directory itself exists and move on.

If the value is a checksum, then the content of the file may be validated using that checksum (see below for details).

How the manifest is used

Both the installer and the upgrader use the manifest to verify that all expected files exist and, optionally, that they have the expected content.

Installer

The installer will walk through the list of files for the version being installed (e.g. the files in the 3.0 list when installing SMF 3.0).

For each file in the list, the installer will check whether it exists. Moreover, if the manifest provided a checksum for that file, then that checksum will be used to verify that the content of that file is as expected.

Upgrader

The upgrader will walk through not only the 3.0 list of files, but also the list of files for whatever version the upgrader is starting from and the lists of files for any intervening versions as well. For example, if upgrading from SMF 2.1.8 to SMF 3.0.1, the upgrader will walk through both the 3.0 list of files and the 2.1 list of files.

Like the installer, the upgrader will check whether each file exists. However, whether the upgrader uses the checksum to validate the file content is complicated:

  • The upgrader will validate the content of the files if the upgrade is from a previous major or minor version of SMF (e.g. 2.1 → 3.0).
  • The upgrader will not validate the content of the files if the upgrade is only from one patch version to another (e.g. 3.0.1 → 3.0.5). In this situation, the upgrader will just check that the files exist. This allows the admin to re-run the upgrader at any time even if installed modification packages have made file changes.

Special handling during active development

During active development, our files are changing all the time. In order to avoid driving us all insane while developing, two forms of special handling are built into the process that checks the manifest:

  • If the current SMF_VERSION string ends with '-dev' and the manifest.php file indicates that files are out of date, a special note is appended to the resulting error message to suggest that the developer should re-run ./other/update_manifest.php and then try the install or upgrade again.
  • If the current SMF_VERSION string ends with '-dev' and the manifest.php file does not exist at all, then the entire check is quietly skipped. This allows us to avoid a situation where every single new commit would require re-running ./other/update_manifest.php.

You may have already noticed that this PR does not actually include a manifest.php file. This is intentional. My plan is that we will only generate and commit a manifest as part of tagging a completed milestone version in Git. Then the very next commit will remove the manifest.php file again. Since that same commit will also involve changing the version number to the next '*-dev' version (see #9674), this will ensure that the second form of special handling kicks back in so that we don't need to continually update the manifest while working on the rest of code.

Compatibility with other pending pull requests

Generally speaking, this change won't affect anything else. The one relevant pending pull request is #9120, which adds migration steps, etc., for upgrading from SMF 1.1, SMF 1.0, and YaBB SE. But even when #9120 has been merged, all that will actually change is that the manifest will contain additional sections listing the files required to perform an upgrade from those earlier versions.

@albertlast

Copy link
Copy Markdown
Collaborator

I like where this is going — the existence spot-check has never been worth much, and a real manifest is the right replacement. A few findings from reading it and exercising the parts that can be run today.

First, a framing note that explains why the rest of this is a list rather than a nit or two: as submitted, none of this code can execute. checkManifest() returns [] immediately when SMF_VERSION ends in -dev and manifest.json is absent, which is the exact state of the branch. So the 9 green checks, and anything a reviewer does by running install.php or upgrade.php, prove only that the branch parses. The code first runs at a release tag.


1. Blocker — the structure check fatals

Sources/Maintenance/Maintenance.php, lines 502-517: the loop iterates $required_versions but reads $manifest['required'] rather than $manifest[$version]. There is no required key in the manifest — ManifestUpdater only ever writes version sections.

The short-circuit makes it unavoidable: as soon as array_key_exists($version, $manifest) is true, the next operand is evaluated. With a well-formed manifest on PHP 8.4:

Warning: Undefined array key "required"
TypeError: array_keys(): Argument #1 ($array) must be of type array, null given

So the first release that ships a manifest.json fatals on install and on upgrade, at the welcome step. Three uses of the wrong key in the one condition.

2. The debug message can never be shown

Both tools set $this->debug from $_REQUEST at the top of the constructor (Install.php:115, Upgrade.php:370), and both constructors then call getProgress() (Install.php:143, Upgrade.php:1414), whose line 1435 in each file does $this->debug = !empty($data['debug']); unconditionally.

Two consequences:

  • error_missing_files_debug — the only variant that names the files — is unreachable in both tools. The admin gets "Unable to find some required files" and no list, which is roughly where we were before.
  • upgradeOptions()'s $_POST['debug'] read is removed by this PR, and that one ran after the constructor, so it worked. The upgrader's debug checkbox is now inert, saveProgress() stores false permanently, and the new checked attribute in UpgradeTemplate.php:352 never fires.

Moving the read into the constructor is right; it needs to land after getProgress(), or getProgress() needs to stop overwriting an explicitly set flag.

3. The manifest leaves out 19 files that we ship

ManifestUpdater builds its ignore list from .gitignore, but git disregards .gitignore for files that are already tracked — and several of ours are. Replicating the filter against a checkout:

EXCLUDED but TRACKED IN GIT   count: 19
  Sources/Unicode/CaseFold.php … Sources/Unicode/SpoofDetector.php   (17 files)
  Packages/backups/.htaccess
  Packages/backups/index.php

prepare_release.php runs UnicodeDataUpdater immediately before ManifestUpdater, so those 17 files are regenerated, committed and shipped — and then filtered back out of the manifest. An admin who fails to upload Sources/Unicode/ passes the integrity check and then hits fatals, which is the failure this PR is for. Deriving the list from git ls-files, or intersecting the scan with it, would fix this and several things below at once.

Two more faults in the same filter:

  • The patterns are matched against $f->getPathname(), which is absolute, while they were built to be repo-relative. $relative_path is computed two lines further down and is what they want. As it stands, a checkout under a dot directory (/home/me/.checkouts/SMF/…) matches the always-ignored dot rule and produces an empty manifest; so does any checkout beneath a directory named cache.
  • Negation precedence is inverted relative to git. The loop tries not_ignored before ignored, so git's last-match-wins is lost — !/Languages/en_US/ now beats the later /Languages/en_US/agreement.txt.

4. The release workflow can't commit the manifest

UpdaterBase::commit() runs git commit -a, which does not stage untracked files. By the plan in the description, manifest.json is untracked at every release — generated at the tag, removed by the next commit. So hasChanged() sees ?? Sources/Maintenance/manifest.json and returns true, commit() finds nothing to commit and returns false without printing anything, and prepare_release.php goes on to print "You may now tag the new release." The tag ships with no manifest.

Related: UpdaterBase::__construct() throws Could not continue. Dirty working tree. on any non-empty git status --porcelain. So the developer escape hatch the error message advertises — "Run ./other/update_manifest.php, then try again" — throws on the second run, because the untracked manifest from the first run has dirtied the tree, and throws for anyone with work in progress.

5. Smaller things

  • ManifestUpdater::build() calls is_dir($path) on the relative path instead of $real_path. Harmless only by luck: every directory in $files is under vendor/, and ~^vendor/(?!index\.php)~ yields the same true either way.
  • Both strings say "Unable to find", but the check also fails on a checksum mismatch — the variable is even named $missing_or_corrupt_files. Someone whose FTP client was in ASCII mode gets ~1800 files reported as missing when all of them are present. Worth a second string, or wording that covers both.
  • The class_exists() sweep over MIGRATIONS/CLEANUPS goes away. The manifest does cover those paths, but only once it exists, so for the whole dev cycle that check is simply gone — and it caught autoloader breakage, which a checksum doesn't.
  • standardizeVersionString() doesn't handle brackets: 17.6 (Debian 17.6-1.pgdg13+1) becomes 17.6.(debian.17.6.1.pgdg.13.1.). version_compare() copes, but the docblock promises a standardized string. In MySQL::cte_support() only $this->version gets standardized and $min_version doesn't. And MariaDB's 5.5.5- protocol prefix still wins: 5.5.5-10.4.32-MariaDB standardizes to 5.5.5.10.4.32.mariadb, which compares as 5.5.5 — same wrong answer as before, so no regression, but the helper doesn't fix it either.

6. One more pending PR is affected

#9120 looks fine to me — its Cleanup/v1_0/, v1_1/ and v2_0/ directories map cleanly onto chooseSection() and VERSION_MAP, and the description's reasoning holds.

But #9681 ("Add PHP version constraint to composer.json") adds "php": ">=8.4" to require, and ManifestUpdater::__construct() maps every require key to vendor/<key>, which build() then resolves with realpath():

Exception: vendor/php does not exist

That takes out both update_manifest.php and prepare_release.php. Filtering the keys to actual packages (str_contains($p, '/')) would cover that and any future ext-* or lib-* entry.

7. Tests

Utils::standardizeVersionString() is a pure static helper and tests/Unit/UtilsTest.php already exists, so a #[DataProvider] over a handful of the version strings we actually see — MariaDB's 5.5.5- prefix, a Debian-packaged PostgreSQL string, 3.0 Alpha 5-dev, 2.1 RC3 — is cheap and would pin the behaviour being relied on in nine call sites.

A fixture-manifest test over checkManifest() would be worth more still: it needs no database and no request, only files, and it would have caught #1 on the first run.

@Sesquipedalian

Copy link
Copy Markdown
Member Author

First, a framing note that explains why the rest of this is a list rather than a nit or two: as submitted, none of this code can execute. checkManifest() returns [] immediately when SMF_VERSION ends in -dev and manifest.json is absent, which is the exact state of the branch. So the 9 green checks, and anything a reviewer does by running install.php or upgrade.php, prove only that the branch parses. The code first runs at a release tag.

This is intentional. During development, we don't want to have to maintain the manifest. Instead, when a reviewer wants to test anything related to the installer or upgrader, then the reviewer can run ./other/update_manifest.php on demand before starting the install or upgrade process. This is similar to how a reviewer must first copy ./other/install.php or ./other/upgrade.php before beginning the install or upgrade process. Still, to help ease that process for automated systems, 384c79e adds some code to .docker/php/entrypoint.sh that will automatically generate manifest.json if it is missing.

  1. Blocker — the structure check fatals

Fixed in bf7e63e.

  1. The debug message can never be shown

Fixed in bbd4c7a.

  1. The manifest leaves out 19 files that we ship

Fixed in adadb9f. Also worth noting that ./Packages/backups/* is intentionally excluded from the manifest. Additionally, fdb6064 removes Sources/Unicode/*.php from .gitignore.

  1. The release workflow can't commit the manifest

Fixed in 3a4d375, with a followup in b1e4da1.

5. Smaller things

  • ManifestUpdater::build() calls is_dir($path) on the relative path instead of $real_path. Harmless only by luck: every directory in $files is under vendor/, and ~^vendor/(?!index\.php)~ yields the same true either way.

Fixed in adadb9f.

  • Both strings say "Unable to find", but the check also fails on a checksum mismatch — the variable is even named $missing_or_corrupt_files. Someone whose FTP client was in ASCII mode gets ~1800 files reported as missing when all of them are present. Worth a second string, or wording that covers both.

Fixed in 1eb36b0.

  • The class_exists() sweep over MIGRATIONS/CLEANUPS goes away. The manifest does cover those paths, but only once it exists, so for the whole dev cycle that check is simply gone — and it caught autoloader breakage, which a checksum doesn't.

Fixed in bd72844.

  • standardizeVersionString() doesn't handle brackets: 17.6 (Debian 17.6-1.pgdg13+1) becomes 17.6.(debian.17.6.1.pgdg.13.1.). version_compare() copes, but the docblock promises a standardized string. In MySQL::cte_support() only $this->version gets standardized and $min_version doesn't. And MariaDB's 5.5.5- protocol prefix still wins: 5.5.5-10.4.32-MariaDB standardizes to 5.5.5.10.4.32.mariadb, which compares as 5.5.5 — same wrong answer as before, so no regression, but the helper doesn't fix it either.

Fixed in 4af75cd.

6. One more pending PR is affected

But #9681 ("Add PHP version constraint to composer.json") adds "php": ">=8.4" to require, and ManifestUpdater::__construct() maps every require key to vendor/<key>, which build() then resolves with realpath():

Fixes in adadb9f.

7. Tests

Utils::standardizeVersionString() is a pure static helper and tests/Unit/UtilsTest.php already exists, so a #[DataProvider] over a handful of the version strings we actually see — MariaDB's 5.5.5- prefix, a Debian-packaged PostgreSQL string, 3.0 Alpha 5-dev, 2.1 RC3 — is cheap and would pin the behaviour being relied on in nine call sites.

Added in 4af75cd.

@albertlast

Copy link
Copy Markdown
Collaborator

Thanks — I went back over all of it, and this time built a real manifest rather than reading the code: cloned the branch, ran other/update_manifest.php for an actual 2000-entry manifest.json, then drove checkManifest() against it.

The fixes hold up. Baseline behaviour on a pristine tree:

install   (start=SMF_VERSION, content=true)        0 reported    79 ms
upgrade   (start=2.1.8,       content=true)        0 reported    68 ms
patch     (start=3.0.1,       content=false)       0 reported     9 ms

Sources/Actions/Post.php deleted                   1 reported
Sources/Actions/Post.php content changed           1 reported
  same, but content=false (patch upgrade)          0 reported

That is the design doing exactly what it says, and the cost is not worth worrying about — ~70 ms for 2000 files. Sources/Unicode/ now lands in the manifest (19 entries), and the git ls-files approach is a much better filter than parsing .gitignore.

Four things still to fix, and one thing I hadn't thought to look at the first time.


1. CI is red — the new test can't run

testStandardizeVersionString(string $input, int $expected) takes int, so all eight rows error out on all four matrix legs:

TypeError: …::testStandardizeVersionString(): Argument #2 ($expected) must be of type int, string given
Tests: 369, Assertions: 579, Errors: 8, Skipped: 44

The docblock on the provider already says array{string, string}.

2. The -dev fallback reports null instead of a filename

bd72844 builds the path with preg_replace(['/^SMF\b/', '/\\/'], …). In single quotes that second pattern is the three characters /\/, so the backslash escapes the closing delimiter and PCRE never finds one. Hiding the manifest and deleting one migration file from the clone:

PHP Warning:  preg_replace(): No ending delimiter '/' found in …/Sources/Maintenance/Maintenance.php on line 462
reported entries: 1
array(1) { [0]=> NULL }

renders as:  <ol><li></li></ol>

It does correctly refuse to continue, but it can't say why. '/\\\\/' is what's wanted. Worth prioritising given your point that this is the path reviewers and developers will actually be on.

3. Nothing under vendor/ reaches the manifest any more

Straight from the generated file:

sections: 3.0 (1837 files)  2.1 (163 files)     total entries: 2000
vendor entries: 0
vendor/autoload.php      *** ABSENT ***
vendor/composer          *** ABSENT ***
vendor/index.php         *** ABSENT ***
vendor/google/recaptcha  *** ABSENT ***
vendor/league/container  *** ABSENT ***

Two independent causes, both in adadb9f:

  • the new package filter asks is_dir(Config::$sourcedir . '/vendor/' . $package), which is <boarddir>/Sources/vendor/… — false for all five packages. Config::$vendordir is presumably what was meant.
  • build()'s new in_array($path, $tracked_files) guard also drops the three hand-listed vendor/ entries, since vendor/ is never tracked. The docblock on $files says those entries "are not subject to filtering", which reads like the intent was for that list to bypass this.

End to end, with a manifest generated by the tool as it stands:

vendor/autoload.php deleted              0 reported
whole vendor/google package deleted      0 reported

That's the case I'd most want caught: vendor/ isn't in anyone's checkout, it's the deepest part of the tree for an FTP client to choke on, and a forum missing it doesn't boot at all. ~^vendor/(?!index\.php)~ in $no_checksum is unreachable now too. The #9681 interaction is genuinely fixed, just by way of switching the feature off.

4. $boarddir is undefined in the missing-manifest branch

bd72844 moved that block above $boarddir = self::getBaseDir();, but it still does Config::$sourcedir ?? $boarddir . DIRECTORY_SEPARATOR . 'Sources':

PHP notice/warning: Undefined variable $boarddir
string(8) "/Sources"

Only reachable when a release build is missing its manifest — which is the one situation that branch exists to report.

5. The manifest is readable over HTTP

This one I missed last time. Sources/ is served by the shipped Apache config, and a .json in it comes back raw:

GET /Sources/Maintenance/manifest.json
HTTP/1.1 200 OK
Content-Type: application/json

So one unauthenticated request returns the full file listing plus the MD5 of 1796 files. Version disclosure isn't new in itself — SMF advertises its version anyway — but this turns "which exact build is this, and has it been patched" into a single GET, including against admins who deliberately strip the version string, and it does it for every forum by default rather than only where the server config is loose.

SMF already has the idiom that sidesteps this: Sources/Unicode/*.php are PHP files returning data behind a SMF guard. Shipping the manifest the same way would close it with no server configuration and no cost to the checks.

6. Smaller

  • The list isn't capped. 25 files uploaded in ASCII mode gave me 25 entries; a genuinely bad upload gives ~1796 <li> elements in one <ol>. Worth truncating with a "…and N more".
  • $this->debug = $this->debug || !empty($data['debug']) makes debug sticky — it can be ticked but never unticked, which is newly visible now that the template renders checked.
  • Stray blank line at the end of the $excluded array in ManifestUpdater. other/ is excluded from php-cs-fixer, so nothing will flag it.

@Sesquipedalian

Sesquipedalian commented Sep 12, 2026 •

Copy link
Copy Markdown
Member Author
  • The list isn't capped. 25 files uploaded in ASCII mode gave me 25 entries; a genuinely bad upload gives ~1796 <li> elements in one <ol>. Worth truncating with a "…and N more".

No. If the admin asks for debug info, they get debug info. That means a list of all the missing files.

@Sesquipedalian

Copy link
Copy Markdown
Member Author

SMF already has the idiom that sidesteps this: Sources/Unicode/*.php are PHP files returning data behind a SMF guard. Shipping the manifest the same way would close it with no server configuration and no cost to the checks.

Excellent idea. This has now been implemented.

All other issues have now been addressed.

@albertlast

Copy link
Copy Markdown
Collaborator

I took this further than reading the diff: I stood up an isolated stack on the branch, restored a real SMF 2.1.7 forum into it, uploaded 3.0 over the top and ran upgrade.php, and separately drove install.php over HTTP with files deliberately deleted and corrupted.

The good news first, because it is most of the story. The checks work. A clean tree installs; deleting Sources/Actions/Post.php or appending a line to a template blocks the installer and withholds the Continue button; restoring the files unblocks it; ?debug=1 lists exactly the offending files. A full 2.1.7 → 3.0 upgrade runs to Upgrade complete! with the check active. The vendor fix, the -dev fallback fix, the $boarddir fix and the manifest.php change all verified good, and the PHP file is served as Content-Length: 0, so the disclosure is properly closed.

Everything below is what is still wrong.


1. A real 2.1 → 3.0 upgrade is blocked at step 1

This is the one I would hold the PR for. On a genuine 2.1.7 forum with the 3.0 package uploaded over it:

2026-09-12T07:31:53+00:00
Step 1: Login
Some required files are either missing or have unexpected content.
Please make sure you uploaded all of the files included in the SMF package and then try again.

The culprits:

attachments/index.php      exists=true   content differs
custom_avatar/index.php    exists=true   content differs

Both are the 2.1 stubs, and they are still 2.1's because those two directories hold the forum's own data — member uploads and avatars — so they survive an upgrade upload when every other directory is replaced. The two versions are not close:

// 2.1 attachments/index.php
if (file_exists(dirname(dirname(__FILE__)) . '/Settings.php'))
{
	require(dirname(dirname(__FILE__)) . '/Settings.php');
	header('location: ' . $boardurl);
}
// 3.0 stub
if (file_exists(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'index.php')) {
	include dirname(__DIR__) . DIRECTORY_SEPARATOR . 'index.php';
}

and the manifest gives both an MD5. I confirmed the diagnosis by copying the 3.0 stub over those two files and changing nothing else — the same run then went all the way through:

Step 7: Finalize Upgrade
Upgrade complete!

Ten checksummed entries sit in directories a live forum owns: attachments/.htaccess, attachments/index.php, custom_avatar/index.php, avatars/index.php, Packages/.htaccess, Packages/index.php, and three under Smileys/. The images next to them are already true; these stubs want the same treatment, or those directories want excluding from content validation.

2. --debug=1 cannot work on the CLI

Which is how I ran into the above with no way to see the file list. parseCliArguments() writes --name=value into $_POST, but the constructors added in bbd4c7a read $_REQUEST, which PHP populated at request start:

isset($_POST["debug"])    = true
isset($_REQUEST["debug"]) = false

The upgradeOptions() code this PR removes read $_POST['debug'], so CLI debug worked before. Over HTTP it is fine — both ?debug=1 and ?debug render the list correctly. Since .docker/install-forum.sh and any CI run drive these tools from the CLI, this is where the file list is least replaceable.

3. The Docker hook adds 75 seconds to every container start, and can crash-loop it

f5a1df7 renamed the manifest, but .docker/php/entrypoint.sh:138 still tests for manifest.json. That file will never exist now, so the hook fires on every single start rather than once. Measured on a clean clone of the branch:

07:25:43  [smf-dev] building manifest.json
07:26:58  Apache ... resuming normal operations

Apache is not started until it finishes, so curl is refused for 75 seconds on every docker compose up and every restart. Hashing ~2000 files across a bind mount is simply slow, and Windows and macOS developers pay it each time.

The bigger problem is the failure mode. entrypoint.sh runs under set -eu and the new line has no || true, so any non-zero exit from update_manifest.php aborts the script before exec "$@". I hit this for real on a checkout where git could not run inside the container:

Fatal error: Uncaught TypeError: preg_match(): Argument #2 ($subject) must be of type string, false given
  in /var/www/html/other/Updaters/UpdaterBase.php:152
$ docker ps -a --filter name=web --format '{{.Status}}'
Restarting (255)

A permanent crash loop rather than a warning. A dirty working tree does the same thing — UpdaterBase throws Could not continue. Dirty working tree. and exits 255, and 2>/dev/null does not suppress it because PHP writes fatals to stdout too. Since a developer's checkout is usually dirty, that is the common case, not the edge case. || true and a test for manifest.php would fix both halves.

4. VersionNumberUpdater no longer removes the manifest

Same rename, second casualty. VersionNumberUpdater.php:136 still runs:

shell_exec('git rm -f --ignore-unmatch ' . escapeshellarg('Sources/Maintenance/manifest.json'));

--ignore-unmatch means this succeeds while removing nothing. So the -dev version bump leaves manifest.php committed, it stays through the next development cycle, and checkManifest() then runs for real against checksums that go stale on the first commit — which is the situation b1e4da1 exists to prevent, and the one the PR description describes as driving everyone insane.

5. A corrupt manifest.php throws instead of being reported

Switching from JSON to PHP lost the error handling with it. The old code wrapped json_decode in try/catch with JSON_THROW_ON_ERROR; the replacement is a bare $manifest = include …manifest.php;. Truncating the file — exactly the incomplete upload this feature detects — gives:

THREW ParseError: syntax error, unexpected string content "d941c6fb5c"

checkManifest() still carries the !is_array($manifest) branch that wants to report this gracefully. A try/catch (\Throwable) around the include restores that.

6. A relocated Themes/ produces 287 false failures

The switch in checkManifest() covers Languages, Packages, Sources and vendor, but not Themes:

Languages moved, Config::$languagesdir set      0 reported
+ Packages moved                                0 reported
+ vendor moved                                  0 reported
+ Themes moved                                287 reported → Themes/default/Admin.template.php …

The three it handles work correctly. Themes is a regression against the check being replaced, which used Maintenance::$theme_dir . '/index.template.php' and so respected a moved theme directory.

7. Smaller

  • </ol> survives into plain text. ToolsBase::logProgress()'s list conversion matches <ol…>, <ul…> and </li> but not the closing tags, so the CLI installer and the progress log get a literal </ol> line under the file list.
  • An unreadable file leaks the server path. Running as the web user against a chmod 000 file, detection is correct but a raw warning lands first: md5_file(/var/www/html/Sources/Actions/Post.php): Failed to open stream: Permission denied. An is_readable() guard would also let the message distinguish a permissions problem, which is a third case that "missing or have unexpected content" does not describe.
  • The -dev fallback drops the extension, reporting Sources/Maintenance/Migration/v3_0/ConvertToInnoDb for a file named ConvertToInnoDb.php.
  • Symlinks are silently skipped at build time. RecursiveDirectoryIterator does not descend into a symlinked subdirectory, so any symlink inside Themes/, Sources/, Languages/, Packages/ or Smileys/ on the machine that cuts a release means those files are quietly absent from the shipped manifest — no error, just a smaller file.
  • Two cosmetic leftovers from the rename: other/update_manifest.php:8 still says the manifest is saved to manifest.json, and the entrypoint logs building manifest.json.

@Sesquipedalian

Copy link
Copy Markdown
Member Author

1. A real 2.1 → 3.0 upgrade is blocked at step 1

The upgrade packages that Simple Machines builds and provides on its website include fresh copies of the index.php and .htaccess files within the attachments, custom_avatar, avatars, Packages, and Smileys directories. Therefore, uploading the entire upgrade package will replace those files on the live forum. If those files fail the checksum test, that means the forum's administrator did not upload the complete package, and the solution is to upload the files that they left out.

2. --debug=1 cannot work on the CLI

Fixed in 8c2b24b.

3. The Docker hook adds 75 seconds to every container start, and can crash-loop it

Fixed in fd43552.

4. VersionNumberUpdater no longer removes the manifest

Fixed in fd43552.

5. A corrupt manifest.php throws instead of being reported

Fixed in f773487.

6. A relocated Themes/ produces 287 false failures

SMF does not support moving ./Themes to a custom location. Therefore, producing failures in this situation is correct.

7. Smaller

  • </ol> survives into plain text. ToolsBase::logProgress()'s list conversion matches <ol…>, <ul…> and </li> but not the closing tags, so the CLI installer and the progress log get a literal </ol> line under the file list.

Fixed in ab0f02a.

  • An unreadable file leaks the server path. Running as the web user against a chmod 000 file, detection is correct but a raw warning lands first: md5_file(/var/www/html/Sources/Actions/Post.php): Failed to open stream: Permission denied. An is_readable() guard would also let the message distinguish a permissions problem, which is a third case that "missing or have unexpected content" does not describe.

Fixed in f773487.

  • The -dev fallback drops the extension, reporting Sources/Maintenance/Migration/v3_0/ConvertToInnoDb for a file named ConvertToInnoDb.php.

Fixed in 26247cb.

  • Symlinks are silently skipped at build time. RecursiveDirectoryIterator does not descend into a symlinked subdirectory, so any symlink inside Themes/, Sources/, Languages/, Packages/ or Smileys/ on the machine that cuts a release means those files are quietly absent from the shipped manifest — no error, just a smaller file.

This is not a concern. There are no symlinks in the SMF repository, and no pull request adding one will ever be approved.

It is worth noting that Git treats symlinks as opaque files (meaning, using git add on a symlink adds the symlink file itself, not the file that the symlink points to, and git checkout re-creates the symlink file itself in the working tree). This means there is no way to accidentally end up with a symlink in one's working tree. Instead, the developer would need to manually and intentionally alter their working tree to do that. That would make the working tree dirty, which would cause an exception to be thrown if the developer then tried to generate a new manifest.

  • Two cosmetic leftovers from the rename: other/update_manifest.php:8 still says the manifest is saved to manifest.json, and the entrypoint logs building manifest.json.

Fixed in fd43552.

@albertlast

Copy link
Copy Markdown
Collaborator

Re-ran everything against 8c2b24b, and extended the coverage into the parts nobody had exercised yet — including a full 2.1.7 → 3.0 upgrade on PostgreSQL.

Verified fixed

Each one checked by running it, not by reading the diff:

CLI --debug parseCliArguments() (Maintenance.php:248) runs before the tool is constructed (:252), and the constructor now reads $_GET/$_POST. The file list prints.
Entrypoint firing every start Now tests manifest.php, so it builds once.
VersionNumberUpdater Now git rms manifest.php.
Corrupt manifest Truncated, garbage, empty, return 'nope';, and returns-nothing all report Sources/Maintenance/manifest.php gracefully.
md5_file() path leak @md5_file() — nothing reaches the page.
</ol> Clean plain-text output.
Missing extension Now …/v3_0/ConvertToInnoDb.php.

Withdrawing the upgrade-block finding

You're right and I'll drop it. I couldn't verify package contents independently — the download site is behind Cloudflare and there's no packaging script in the repo — and you're the one who builds them.

I did check the one thing that could still have bitten: whether SMF's own Security::secureDirectory() writes a stub that differs from the shipped one, which would mean a forum could fail the checksum even after a complete upload. It doesn't — byte-identical, md5 5af5d3f12a31e6e2b6e24e21865a2aa8, matching the manifest entry exactly. So a complete upload passes, and there's no second path to a mismatch. Withdrawn.

Also taking your point on symlinks — git storing them opaquely plus the dirty-tree guard does close that off. And Themes is your call; I'll note only that Admin/Themes.php:239-241 writes theme_dir from $_POST['reset_dir'], so the stored value can differ from Themes/default, and leave it there.

Newly covered, all passing

These were the parts with no coverage at all, so they seemed worth exercising before the PR lands.

Version sectioning — the actual novel idea here, and in my earlier upgrade run both sections passed trivially, so it proved nothing. Deleting a file that exists only in the 2.1 section:

upgrade from 2.1.7  (2.1 + 3.0 sections)     1 reported  Sources/Db/Schema/v2_1/AdminInfoFiles.php
patch  from 3.0.1   (3.0 section only)       0 reported
patch  from 3.0.1, content=true              0 reported
fresh install (start = SMF_VERSION)          0 reported

Consulted on a major upgrade, invisible to a patch upgrade and to a fresh install. Exactly as designed.

A relocated Sources/ — the one switch case never exercised (I'd only moved Languages, Packages and vendor before). With Sources outside the board directory and Config::$sourcedir pointed at it: 0 reported.

PostgreSQL. A real 2.1.7 baseline restored into a Postgres stack (0 errors on load), 3.0 uploaded over it, upgrade.php run:

 +++ Fixing sequences (PostgreSQL)... ....................................done.
 +++ Adding FIND_IN_SET function (PostgreSQL)... done.
 …
smfVersion = 3.0 Alpha 5-dev

Afterwards: index.php, ?action=help and ?action=credits all 200; 24 boards, 1200 topics, 6000 posts, 403 members intact; no ERROR/FATAL in the Postgres container log; nothing manifest-related in smf_log_errors. Both engines behave identically.

(Two unrelated things showed up in that log and I'll leave them out of this PR: 2.1-era rows still in smf_background_tasks whose classes don't exist in 3.0 — CreatePost_Notify_Background, Update_TLD_Regex — and a JSON decode error: Malformed UTF-8 attributed to Upgrade.php, which looks like getProgress() logging before its own try/catch swallows it. Happy to file either separately if they're not already known.)

Still open

1. The entrypoint crash loop is only half fixed. The filename is right now, but set -eu is still on line 4 and line 140 still has no guard:

php -f "$BOARD_DIR/other/update_manifest.php" 2>/dev/null

Any non-zero exit aborts the script before exec "$@", so Apache never starts and the container restarts forever. UpdaterBase throws Could not continue. Dirty working tree. and exits 255 — and a developer's checkout is usually dirty, so that is the common case rather than an edge one. 2>/dev/null doesn't help either, since PHP writes fatals to stdout as well. Worth noting that lines 115 and 129 of the same script already guard themselves with || true.

2. A manifest.php that isn't PHP gets echoed into the install page. f773487 caught the throwing case but not this one — include emits any non-PHP text before returning:

<<<BEGIN
<html><body><h1>413 Request Entity Too Large</h1></body></html>
END>>>
reported: 1 -> Sources/Maintenance/manifest.php

A truncated upload through a proxy leaves an error page as readily as a half-written file. The detection is right; only the contents leaking first is the problem, and an ob_start()/ob_get_clean() around the include would settle it.

3. Install.php:363 still assigns from $_REQUEST. At the end of welcome():

$this->debug = isset($_REQUEST['debug']);

That's the same $_REQUEST-versus-CLI mismatch 8c2b24b fixed in the constructor, 250 lines further down. The manifest list still prints, because it's produced before line 363 — but debug is then switched back off for every later step and persisted as false by saveProgress().

One for a different PR

prepare_release.php fatals when given an explicit version:

$ php -f prepare_release.php 3.0
PHP Fatal error:  Uncaught Error: Class "SMF\other\Updaters\VersionNumberUpdater" not found
  in other/prepare_release.php:51

Line 50 reads Updaters\VersionNumberUpdater::VERSION_PATTERN to validate $argv[1], but only UpdaterBase.php has been required by then and the autoloader is registered inside UpdaterBase::__construct(), which hasn't run. Without an argument it's fine, because isset($argv[1]) short-circuits and the loop requires each file before use.

This is pre-existing on release-3.0 (it arrived with 8173ba6, and this PR touches the file with a single line), so it isn't yours to fix here. I mention it only because this PR makes that script the sole way a manifest is ever produced, and passing an explicit version is exactly what you'd do when tagging a milestone. Say the word and I'll open it separately.

Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
@Sesquipedalian
Sesquipedalian removed the request for review from jdarwood007 September 13, 2026 04:03
@Sesquipedalian

Copy link
Copy Markdown
Member Author

All issues have been addressed, and I have rebased to clean up the commit history.

The fatal error in prepare_release.php has also been fixed, so no need for a separate PR.

@Sesquipedalian
Sesquipedalian merged commit 0d2d622 into SimpleMachines:release-3.0 Sep 13, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants