|
| 1 | +/** |
| 2 | + * https://github.com/facebook/zstd/blob/dev/examples/streaming_decompression.c |
| 3 | + */ |
| 4 | + |
| 5 | +import cpp |
| 6 | +import DecompressionBomb |
| 7 | + |
| 8 | +/** |
| 9 | + * The `ZSTD_decompress` function is used in flow sink. |
| 10 | + */ |
| 11 | +class ZstdDecompressFunction extends DecompressionFunction { |
| 12 | + ZstdDecompressFunction() { this.hasGlobalName("ZSTD_decompress") } |
| 13 | + |
| 14 | + override int getArchiveParameterIndex() { result = 2 } |
| 15 | +} |
| 16 | + |
| 17 | +/** |
| 18 | + * The `ZSTD_decompressDCtx` function is used in flow sink. |
| 19 | + */ |
| 20 | +class ZstdDecompressDctxFunction extends DecompressionFunction { |
| 21 | + ZstdDecompressDctxFunction() { this.hasGlobalName("ZSTD_decompressDCtx") } |
| 22 | + |
| 23 | + override int getArchiveParameterIndex() { result = 3 } |
| 24 | +} |
| 25 | + |
| 26 | +/** |
| 27 | + * The `ZSTD_decompressStream` function is used in flow sink. |
| 28 | + */ |
| 29 | +class ZstdDecompressStreamFunction extends DecompressionFunction { |
| 30 | + ZstdDecompressStreamFunction() { this.hasGlobalName("ZSTD_decompressStream") } |
| 31 | + |
| 32 | + override int getArchiveParameterIndex() { result = 2 } |
| 33 | +} |
| 34 | + |
| 35 | +/** |
| 36 | + * The `ZSTD_decompress_usingDDict` function is used in flow sink. |
| 37 | + */ |
| 38 | +class ZstdDecompressUsingDdictFunction extends DecompressionFunction { |
| 39 | + ZstdDecompressUsingDdictFunction() { this.hasGlobalName("ZSTD_decompress_usingDDict") } |
| 40 | + |
| 41 | + override int getArchiveParameterIndex() { result = 3 } |
| 42 | +} |
| 43 | + |
| 44 | +/** |
| 45 | + * The `fopen_orDie` function as a flow step. |
| 46 | + */ |
| 47 | +class FopenOrDieFunctionStep extends DecompressionFlowStep { |
| 48 | + FopenOrDieFunctionStep() { this = "FopenOrDieFunctionStep" } |
| 49 | + |
| 50 | + override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) { |
| 51 | + exists(FunctionCall fc | fc.getTarget().hasGlobalName("fopen_orDie") | |
| 52 | + node1.asIndirectExpr() = fc.getArgument(0) and |
| 53 | + node2.asExpr() = fc |
| 54 | + ) |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +/** |
| 59 | + * The `fread_orDie` function as a flow step. |
| 60 | + */ |
| 61 | +class FreadOrDieFunctionStep extends DecompressionFlowStep { |
| 62 | + FreadOrDieFunctionStep() { this = "FreadOrDieFunctionStep" } |
| 63 | + |
| 64 | + override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) { |
| 65 | + exists(FunctionCall fc | fc.getTarget().hasGlobalName("fread_orDie") | |
| 66 | + node1.asExpr() = fc.getArgument(2) and |
| 67 | + node2.asIndirectExpr() = fc.getArgument(0) |
| 68 | + ) |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +/** |
| 73 | + * The `src` member of a `ZSTD_inBuffer` variable is used in a flow steps. |
| 74 | + */ |
| 75 | +class SrcMember extends DecompressionFlowStep { |
| 76 | + SrcMember() { this = "SrcMember" } |
| 77 | + |
| 78 | + override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) { |
| 79 | + exists(VariableAccess inBufferAccess, Field srcField, ClassAggregateLiteral c | |
| 80 | + inBufferAccess.getType().hasName("ZSTD_inBuffer") and |
| 81 | + srcField.hasName("src") |
| 82 | + | |
| 83 | + node2.asExpr() = inBufferAccess and |
| 84 | + inBufferAccess.getTarget().getInitializer().getExpr() = c and |
| 85 | + node1.asIndirectExpr() = c.getFieldExpr(srcField, _) |
| 86 | + ) |
| 87 | + } |
| 88 | +} |
0 commit comments