Sniffs: fields the sniffs read from codecs / containers (Aac.adts, IsoBmff.sniff, Zstd.MAGIC, ...) copied once onto shared proxies, so detection loads no codec chunk; chunked build: a Detect chunk (Sniffs + what it requires); Brotli: static dictionary inflated on first reference (a trial decode no longer loads Deflate)
This commit is contained in:
1 parent
d64adc978f
commit
3468bfb49a
14 files changed
+8966
-5389
No files matched your search
+15
-15
@@ -390,7 +390,7 @@ local list: { Entry } = {
|
||||
mime = { "audio/aac", "audio/aacp", "audio/x-aac" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "codecs/audio/Aac", "codecs/audio/Pcm", "codecs/audio/Stream" },
|
||||
caps = { decode = true, encode = false, codecs = { "aac" }, streaming = true },
|
||||
sniff = 1,
|
||||
sniff = 0,
|
||||
load = function()
|
||||
return require("@rosetta/audio/aac")
|
||||
end,
|
||||
@@ -403,7 +403,7 @@ local list: { Entry } = {
|
||||
mime = { "audio/ac3", "audio/x-ac3" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "codecs/audio/Pcm", "codecs/audio/Stream", "codecs/audio/Ac3" },
|
||||
caps = { decode = true, encode = false, codecs = { "ac3" }, channels = 6, streaming = true, lossy = true },
|
||||
sniff = 1,
|
||||
sniff = 0,
|
||||
load = function()
|
||||
return require("@rosetta/audio/ac3")
|
||||
end,
|
||||
@@ -521,7 +521,7 @@ local list: { Entry } = {
|
||||
mime = { "audio/mp4", "audio/x-m4a", "audio/m4a" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "containers/IsoBmff", "codecs/audio/Aac", "codecs/audio/Alac", "codecs/audio/Pcm", "codecs/audio/Stream" },
|
||||
caps = { decode = true, encode = true, codecs = { "aac", "alac" }, encodeCodecs = { "alac" }, tags = true, streaming = true },
|
||||
sniff = 1,
|
||||
sniff = 0,
|
||||
load = function()
|
||||
return require("@rosetta/audio/m4a")
|
||||
end,
|
||||
@@ -534,7 +534,7 @@ local list: { Entry } = {
|
||||
mime = { "audio/mpeg", "audio/mp3", "audio/mpa" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "codecs/audio/Pcm", "codecs/audio/Resample", "codecs/audio/Mpa/Header", "codecs/audio/Mpa/Core", "codecs/audio/Mpa/Encode3", "codecs/audio/Mpa/Encode2" },
|
||||
caps = { decode = true, encode = true, streaming = true, seek = true, layers = { 1, 2, 3 }, encodeLayers = { 2, 3 }, channels = 2 },
|
||||
sniff = 1,
|
||||
sniff = 0,
|
||||
load = function()
|
||||
return require("@rosetta/audio/mp3")
|
||||
end,
|
||||
@@ -547,7 +547,7 @@ local list: { Entry } = {
|
||||
mime = { "audio/x-musepack", "audio/musepack" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "codecs/audio/Pcm", "codecs/audio/Stream", "codecs/audio/ApeTag", "codecs/audio/Musepack" },
|
||||
caps = { decode = true, encode = false, codecs = { "musepack" }, versions = { 7, 8 }, streaming = true, lossy = true },
|
||||
sniff = 1,
|
||||
sniff = 0,
|
||||
load = function()
|
||||
return require("@rosetta/audio/mpc")
|
||||
end,
|
||||
@@ -638,7 +638,7 @@ local list: { Entry } = {
|
||||
mime = { "audio/wav", "audio/x-wav", "audio/wave", "audio/vnd.wave" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "containers/Riff", "codecs/audio/Pcm", "codecs/audio/Adpcm" },
|
||||
caps = { decode = true, encode = true, streaming = true, depths = { 8, 16, 24, 32 }, float = true, rf64 = true },
|
||||
sniff = 1,
|
||||
sniff = 0,
|
||||
load = function()
|
||||
return require("@rosetta/audio/wav")
|
||||
end,
|
||||
@@ -730,7 +730,7 @@ local list: { Entry } = {
|
||||
mime = { "video/mp4", "video/quicktime", "video/3gpp" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "containers/IsoBmff", "containers/Demux", "codecs/video/Video", "codecs/video/Video/Source" },
|
||||
caps = { decode = true, encode = true, streaming = true, remux = true, video = { "mjpeg", "mpeg1", "mpeg2", "h264" }, audio = true, fragments = true },
|
||||
sniff = 1,
|
||||
sniff = 0,
|
||||
load = function()
|
||||
return require("@rosetta/video/mp4")
|
||||
end,
|
||||
@@ -834,7 +834,7 @@ local list: { Entry } = {
|
||||
mime = { "model/x-ase", "text/plain" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "codecs/text/Text", "codecs/model/Mat4" },
|
||||
caps = { decode = true, encode = true, text = true, materials = true, cameras = true, lights = true, vertexColors = true },
|
||||
sniff = 1,
|
||||
sniff = 0,
|
||||
load = function()
|
||||
return require("@rosetta/model/ase")
|
||||
end,
|
||||
@@ -925,7 +925,7 @@ local list: { Entry } = {
|
||||
mime = { "application/vnd.autodesk.fbx", "model/fbx" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "codecs/compress/Deflate", "core/Base64", "codecs/model/Mat4" },
|
||||
caps = { decode = true, encode = true, binary = true, ascii = true, materials = true, animation = true, skins = true, morphTargets = true, cameras = true, lights = true, polygons = true },
|
||||
sniff = 2,
|
||||
sniff = 0,
|
||||
load = function()
|
||||
return require("@rosetta/model/fbx")
|
||||
end,
|
||||
@@ -1081,7 +1081,7 @@ local list: { Entry } = {
|
||||
mime = { "application/x-ms3d" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "codecs/model/Mat4", "codecs/model/MeshFlatten" },
|
||||
caps = { decode = true, encode = true, materials = true, skins = true, animation = true },
|
||||
sniff = 1,
|
||||
sniff = 0,
|
||||
load = function()
|
||||
return require("@rosetta/model/ms3d")
|
||||
end,
|
||||
@@ -1682,7 +1682,7 @@ local list: { Entry } = {
|
||||
mime = { "application/x-fat-image" },
|
||||
deps = { "core/Err", "core/Bytes", "containers/Archive", "containers/Fat" },
|
||||
caps = { decode = true, encode = true, variants = { "fat12", "fat16", "fat32" } },
|
||||
sniff = 1,
|
||||
sniff = 0,
|
||||
load = function()
|
||||
return require("@rosetta/archive/fat")
|
||||
end,
|
||||
@@ -1812,7 +1812,7 @@ local list: { Entry } = {
|
||||
mime = { "application/x-tar" },
|
||||
deps = { "core/Err", "core/Bytes", "containers/Archive", "containers/Tar" },
|
||||
caps = { decode = true, encode = true, variants = { "ustar", "pax", "gnu" } },
|
||||
sniff = 1,
|
||||
sniff = 0,
|
||||
load = function()
|
||||
return require("@rosetta/archive/tar")
|
||||
end,
|
||||
@@ -2137,7 +2137,7 @@ local list: { Entry } = {
|
||||
mime = { "text/x-vdf" },
|
||||
deps = { "core/Err", "core/Bytes", "core/Sniff", "codecs/text/KeyValues" },
|
||||
caps = { decode = true, encode = true, ordered = true, binary = true },
|
||||
sniff = 1,
|
||||
sniff = 0,
|
||||
load = function()
|
||||
return require("@rosetta/data/vdf")
|
||||
end,
|
||||
@@ -2501,7 +2501,7 @@ local list: { Entry } = {
|
||||
mime = { "audio/x-soundfont" },
|
||||
deps = { "core/Err", "core/Bytes", "codecs/audio/SoundFont" },
|
||||
caps = { decode = true, encode = false, sm24 = true, sf3 = false },
|
||||
sniff = 1,
|
||||
sniff = 0,
|
||||
load = function()
|
||||
return require("@rosetta/music/sf2")
|
||||
end,
|
||||
@@ -2592,7 +2592,7 @@ local list: { Entry } = {
|
||||
mime = { "audio/x-scpls", "audio/scpls" },
|
||||
deps = { "core/Err", "core/Bytes", "Types", "codecs/text/Url", "codecs/text/Text", "core/Sniff" },
|
||||
caps = { decode = true, encode = true },
|
||||
sniff = 1,
|
||||
sniff = 0,
|
||||
load = function()
|
||||
return require("@rosetta/playlist/pls")
|
||||
end,
|
||||
|
||||
+893
-69
File diff suppressed because it is too large.
Load diff
@@ -10,8 +10,11 @@ local bcreate, bcopy, blen, bfill = buffer.create, buffer.copy, buffer.len, buff
|
||||
|
||||
local Decode = {}
|
||||
|
||||
local NO_DICTIONARY = "static dictionary unavailable"
|
||||
Decode.NO_DICTIONARY = NO_DICTIONARY
|
||||
|
||||
export type Static = {
|
||||
dictionary: buffer, -- 122784 bytes
|
||||
dictionary: () -> buffer?, -- 122784 bytes, on first use (nil: Decode.NO_DICTIONARY)
|
||||
context: buffer, -- 2048 bytes: 4 modes x (256 for p1, 256 for p2)
|
||||
prefixSuffix: buffer, -- length-prefixed strings
|
||||
prefixSuffixMap: { number },
|
||||
@@ -516,7 +519,7 @@ function Decode.decompress(src: buffer, off: number, len: number, maxBytes: numb
|
||||
end
|
||||
local maxBackward = 2 ^ wbits - 16
|
||||
|
||||
local dict = S.dictionary
|
||||
local dict: buffer? = nil
|
||||
local LUT = S.context
|
||||
local PS = S.prefixSuffix
|
||||
local PSMAP = S.prefixSuffixMap
|
||||
@@ -885,6 +888,12 @@ function Decode.decompress(src: buffer, off: number, len: number, maxBytes: numb
|
||||
end
|
||||
local ws = w
|
||||
if wl > 0 then
|
||||
if dict == nil then
|
||||
dict = S.dictionary()
|
||||
if dict == nil then
|
||||
return nil, NO_DICTIONARY
|
||||
end
|
||||
end
|
||||
bcopy(WORD, w, dict, wo, wl)
|
||||
w += wl
|
||||
end
|
||||
|
||||
@@ -6,7 +6,6 @@ local Err = require("@rosetta/core/Err")
|
||||
local Bytes = require("@rosetta/core/Bytes")
|
||||
local Crc32 = require("@rosetta/core/Crc32")
|
||||
local Base64 = require("@rosetta/core/Base64")
|
||||
local Deflate = require("@rosetta/codecs/compress/Deflate")
|
||||
local Decode = require("@rosetta/codecs/compress/Brotli/Decode")
|
||||
local StaticData = require("@rosetta/codecs/compress/Brotli/Static")
|
||||
|
||||
@@ -23,32 +22,46 @@ local function unbase64(s: string): buffer
|
||||
end
|
||||
|
||||
local static: Decode.Static? = nil
|
||||
local dictionary: buffer? = nil
|
||||
local dictionaryErr: Err.Err? = nil
|
||||
|
||||
local function tables(): (Decode.Static?, Err.Err?)
|
||||
if static then
|
||||
return static, nil
|
||||
-- inflated on the first dictionary reference (RFC 7932 section 8)
|
||||
local function loadDictionary(): buffer?
|
||||
if dictionary or dictionaryErr then
|
||||
return dictionary
|
||||
end
|
||||
local Deflate = require("@rosetta/codecs/compress/Deflate")
|
||||
local z = unbase64(table.concat(StaticData.dictionary))
|
||||
local dict, err = Deflate.zlib(z, 0, nil, StaticData.dictionarySize)
|
||||
if not dict then
|
||||
return nil, err
|
||||
dictionaryErr = err
|
||||
return nil
|
||||
end
|
||||
if Crc32.of(dict) ~= StaticData.dictionaryCrc then
|
||||
return nil, Err.new(Err.CHECKSUM, "brotli: static dictionary damaged")
|
||||
dictionaryErr = Err.new(Err.CHECKSUM, "brotli: static dictionary damaged")
|
||||
return nil
|
||||
end
|
||||
static = {
|
||||
dictionary = dict,
|
||||
dictionary = dict
|
||||
return dict
|
||||
end
|
||||
|
||||
local function tables(): Decode.Static
|
||||
if static then
|
||||
return static
|
||||
end
|
||||
local s: Decode.Static = {
|
||||
dictionary = loadDictionary,
|
||||
context = unbase64(table.concat(StaticData.context)),
|
||||
prefixSuffix = unbase64(StaticData.prefixSuffix),
|
||||
prefixSuffixMap = StaticData.prefixSuffixMap,
|
||||
transforms = StaticData.transforms,
|
||||
}
|
||||
return static, nil
|
||||
static = s
|
||||
return s
|
||||
end
|
||||
|
||||
function Brotli.dictionary(): buffer?
|
||||
local s = tables()
|
||||
return if s then s.dictionary else nil
|
||||
return loadDictionary()
|
||||
end
|
||||
|
||||
function Brotli.decompress(buf: buffer | string, offset: number?, length: number?, opts: Options?): (buffer?, any)
|
||||
@@ -64,12 +77,11 @@ function Brotli.decompress(buf: buffer | string, offset: number?, length: number
|
||||
if l == 0 then
|
||||
return nil, Err.new(Err.TRUNCATED, "brotli: empty input", o)
|
||||
end
|
||||
local S, serr = tables()
|
||||
if not S then
|
||||
return nil, serr
|
||||
end
|
||||
local out, size, consumed = Decode.decompress(b, o, l, maxBytes, S, large)
|
||||
local out, size, consumed = Decode.decompress(b, o, l, maxBytes, tables(), large)
|
||||
if not out then
|
||||
if size == Decode.NO_DICTIONARY and dictionaryErr then
|
||||
return nil, dictionaryErr
|
||||
end
|
||||
local e = Err.from(size, o)
|
||||
e.message = "brotli: " .. e.message
|
||||
return nil, e
|
||||
|
||||
Reference in new issue
Block a user