You've already forked AstralRinth
forked from didirus/AstralRinth
feat(labrinth): allow protected resource and data packs to pass validation (#3792)
* fix(labrinth): return version artifact size exceeded error eagerly Now we don't wait until the result memory buffer has grown to a size greater than the maximum allowed, and instead we return such an error before the buffer is grown with the current chunk, which should reduce memory usage. * fix(labrinth): proper supported game versions range for datapacks * feat(labrinth): allow protected resource and data packs to pass validation
This commit is contained in:
committed by
GitHub
parent
97e4d8e132
commit
fb30c0ba2b
@@ -1,7 +1,8 @@
|
||||
use crate::validate::{
|
||||
SupportedGameVersions, ValidationError, ValidationResult,
|
||||
MaybeProtectedZipFile, PLAUSIBLE_PACK_REGEX, SupportedGameVersions,
|
||||
ValidationError, ValidationResult,
|
||||
};
|
||||
use std::io::Cursor;
|
||||
use std::{io::Cursor, sync::LazyLock};
|
||||
use zip::ZipArchive;
|
||||
|
||||
pub struct ShaderValidator;
|
||||
@@ -83,25 +84,42 @@ impl super::Validator for CoreShaderValidator {
|
||||
SupportedGameVersions::All
|
||||
}
|
||||
|
||||
fn validate(
|
||||
fn validate_maybe_protected_zip(
|
||||
&self,
|
||||
archive: &mut ZipArchive<Cursor<bytes::Bytes>>,
|
||||
file: &mut MaybeProtectedZipFile,
|
||||
) -> Result<ValidationResult, ValidationError> {
|
||||
if archive.by_name("pack.mcmeta").is_err() {
|
||||
return Ok(ValidationResult::Warning(
|
||||
"No pack.mcmeta present for pack file. Tip: Make sure pack.mcmeta is in the root directory of your pack!",
|
||||
));
|
||||
};
|
||||
static VANILLA_SHADER_CEN_ENTRY_REGEX: LazyLock<regex::bytes::Regex> =
|
||||
LazyLock::new(|| {
|
||||
regex::bytes::RegexBuilder::new(concat!(
|
||||
r"\x50\x4b\x01\x02", // CEN signature
|
||||
r".{24}", // CEN fields
|
||||
r".{2}", // CEN file name length
|
||||
r".{16}", // More CEN fields
|
||||
r"assets/minecraft/shaders/", // CEN file name
|
||||
))
|
||||
.unicode(false)
|
||||
.dot_matches_new_line(true)
|
||||
.build()
|
||||
.unwrap()
|
||||
});
|
||||
|
||||
if !archive
|
||||
.file_names()
|
||||
.any(|x| x.starts_with("assets/minecraft/shaders/"))
|
||||
{
|
||||
return Ok(ValidationResult::Warning(
|
||||
"No shaders folder present for vanilla shaders.",
|
||||
));
|
||||
if match file {
|
||||
MaybeProtectedZipFile::Unprotected(archive) => {
|
||||
archive.by_name("pack.mcmeta").is_ok()
|
||||
&& archive
|
||||
.file_names()
|
||||
.any(|x| x.starts_with("assets/minecraft/shaders/"))
|
||||
}
|
||||
MaybeProtectedZipFile::MaybeProtected { data, .. } => {
|
||||
PLAUSIBLE_PACK_REGEX.is_match(data)
|
||||
&& VANILLA_SHADER_CEN_ENTRY_REGEX.is_match(data)
|
||||
}
|
||||
} {
|
||||
Ok(ValidationResult::Pass)
|
||||
} else {
|
||||
Ok(ValidationResult::Warning(
|
||||
"No pack.mcmeta or vanilla shaders folder present for pack file. Tip: Make sure pack.mcmeta is in the root directory of your pack!",
|
||||
))
|
||||
}
|
||||
|
||||
Ok(ValidationResult::Pass)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user