Merge pull request #21002 from github/tausbn/python-add-models-for-zstd-compression

Python: Add modelling for `zstd.compression`
This commit is contained in:
Taus
2026-01-09 14:05:06 +01:00
committed by GitHub
4 changed files with 79 additions and 24 deletions

View File

@@ -364,6 +364,46 @@ module Lzma {
}
}
/** Provides sinks and additional taint steps related to the `zstd` library in Python 3.14+. */
module Zstd {
private API::Node zstdInstance() {
result = API::moduleImport("compression").getMember("zstd").getMember(["ZstdFile", "open"])
}
/**
* The Decompression Sinks of `zstd` library
*
* `zstd.open(sink)`
* `zstd.ZstdFile(sink)`
*
* only read mode is sink
*/
class DecompressionSink extends DecompressionBomb::Sink {
DecompressionSink() {
exists(API::CallNode zstdCall | zstdCall = zstdInstance().getACall() |
this = zstdCall.getParameter(0, "file").asSink() and
(
not exists(
zstdCall
.getParameter(1, "mode")
.getAValueReachingSink()
.asExpr()
.(StringLiteral)
.getText()
) or
zstdCall
.getParameter(1, "mode")
.getAValueReachingSink()
.asExpr()
.(StringLiteral)
.getText()
.matches("%r%")
)
)
}
}
}
/**
* `io.TextIOWrapper(ip, encoding='utf-8')` like following:
* ```python