{"record":{"id":"9abb2572596933c7","repo":"peass-ng/PEASS-ng","slug":"must-be-in-the-range-1-to-7","errorCode":null,"errorMessage":"must be in the range 1 to 7","messagePattern":"must be in the range 1 to 7","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/digests/KeccakDigest.cs","lineNumber":204,"sourceCode":"                count += available;\n                KeccakAbsorb(dataQueue, 0);\n            }\n\n            int remaining;\n            while ((remaining = (len - count)) >= rateBytes)\n            {\n                KeccakAbsorb(data, off + count);\n                count += rateBytes;\n            }\n\n            Array.Copy(data, off + count, dataQueue, 0, remaining);\n            this.bitsInQueue = remaining << 3;\n        }\n\n        protected void AbsorbBits(int data, int bits)\n        {\n            if (bits < 1 || bits > 7)\n                throw new ArgumentException(\"must be in the range 1 to 7\", \"bits\");\n            if ((bitsInQueue & 7) != 0)\n                throw new InvalidOperationException(\"attempt to absorb with odd length queue\");\n            if (squeezing)\n                throw new InvalidOperationException(\"attempt to absorb while squeezing\");\n\n            int mask = (1 << bits) - 1;\n            dataQueue[bitsInQueue >> 3] = (byte)(data & mask);\n\n            // NOTE: After this, bitsInQueue is no longer a multiple of 8, so no more absorbs will work\n            bitsInQueue += bits;\n        }\n\n        private void PadAndSwitchToSqueezingPhase()\n        {\n            Debug.Assert(bitsInQueue < rate);\n\n            dataQueue[bitsInQueue >> 3] |= (byte)(1 << (bitsInQueue & 7));\n","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/crypto/digests/KeccakDigest.cs#L186-L222","documentation":"KeccakDigest.AbsorbBits(int, int) throws ArgumentException when the `bits` parameter is outside 1..7. AbsorbBits exists to absorb a sub-byte (partial byte) quantity; absorbing 0 or 8+ bits makes no sense — 8 bits go through the byte Absorb path. Called from the partial-byte DoFinal path.","triggerScenarios":"Passing partialBits = 0 or partialBits > 7 to the extended DoFinal(output, outOff, partialByte, partialBits) overload, which forwards to AbsorbBits.","commonSituations":"Generic hashing wrappers computing partialBits from a bit-length count where the count is byte-aligned (yields 0) or mis-clamped; ported code from APIs that allow 0 partial bits.","solutions":["Clamp/validate partialBits to 1..7 before calling; when no partial bits remain, use the plain DoFinal overload.","Use plain DoFinal(output, outOff) when input is byte-aligned.","Guard bit-count math so trailing bits are computed as (totalBits % 8) and skipped when 0."],"exampleFix":"// before\nint partialBits = totalBits % 8; // can be 0\ndigest.DoFinal(outBytes, 0, partialByte, partialBits); // throws when 0\n// after\nif (totalBits % 8 == 0)\n    digest.DoFinal(outBytes, 0);\nelse\n    digest.DoFinal(outBytes, 0, partialByte, totalBits % 8);","handlingStrategy":"validation","validationCode":"if (partialBits < 1 || partialBits > 7)\n    throw new ArgumentOutOfRangeException(nameof(partialBits), \"must be in the range 1 to 7\");\ndigest.DoFinal(output, outOff, partialByte, partialBits);","typeGuard":"bool IsValidPartialBits(int bits) => bits >= 1 && bits <= 7;","tryCatchPattern":"try { digest.DoFinal(outBuf, 0, partialByte, partialBits); } catch (ArgumentException ex) when (ex.ParamName == \"bits\") { digest.DoFinal(outBuf, 0); // byte-aligned fallback }","preventionTips":["Compute partialBits as totalBits % 8 and use the plain DoFinal when it is 0.","Add parameter range assertions at API boundaries.","Prefer byte-aligned hashing; reserve AbsorbBits for protocols that genuinely need bit granularity."],"tags":["csharp","bouncycastle","keccak","argument-validation"],"backgroundTag":"invalid-argument-range","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}