{"record":{"id":"3f50228e89192adf","repo":"stride3d/stride","slug":"count-cannot-be-less-than-zero","errorCode":null,"errorMessage":"Count cannot be less than zero","messagePattern":"Count cannot be less than zero","errorType":"validation","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.IO/System.IO.Compression.Zip/Crc32.cs","lineNumber":121,"sourceCode":"        /// <param name=\"buffer\">\n        /// The buffer which contains the data\n        /// </param>\n        /// <param name=\"offset\">\n        /// The offset in the buffer where the data starts\n        /// </param>\n        /// <param name=\"count\">\n        /// The number of data bytes to update the CRC with.\n        /// </param>\n        public void Update(byte[] buffer, int offset, int count)\n        {\n            if (buffer == null)\n            {\n                throw new ArgumentNullException(\"buffer\");\n            }\n\n            if (count < 0)\n            {\n                throw new ArgumentOutOfRangeException(\"count\", \"Count cannot be less than zero\");\n            }\n\n            if (offset < 0 || offset + count > buffer.Length)\n            {\n                throw new ArgumentOutOfRangeException(\"offset\");\n            }\n\n            this.Value ^= CrcSeed;\n\n            while (--count >= 0)\n            {\n                this.Value = Crc32Table[(this.Value ^ buffer[offset++]) & 0xFF] ^ (this.Value >> 8);\n            }\n\n            this.Value ^= CrcSeed;\n        }\n\n        #endregion","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.IO/System.IO.Compression.Zip/Crc32.cs#L103-L139","documentation":"Argument validation in Crc32.Update: the count parameter is negative, which cannot describe a number of bytes to process. The faulting input is the count argument; buffer/offset were already accepted.","triggerScenarios":"Calling Update(buffer, offset, count) with count computed from an expression that went negative (e.g. stream length subtraction, leftover = length - position underflow).","commonSituations":"Hashing a stream in chunks where remaining bytes calculation underflows, or passing -1 as a 'default' value.","solutions":["Clamp or assert count >= 0 before calling Update","Recompute the remaining-bytes expression, e.g. (int)Math.Min(chunkSize, stream.Length - stream.Position)","If no bytes remain, skip the Update call entirely"],"exampleFix":"// before\ncrc.Update(buffer, 0, (int)(expected - read)); // can be negative\n// after\nint remaining = (int)(expected - read);\nif (remaining > 0) crc.Update(buffer, 0, Math.Min(remaining, buffer.Length));","handlingStrategy":"validation","validationCode":"int remaining = (int)(total - processed);\nif (remaining < 0) throw new InvalidOperationException(\"Underflow in remaining-byte calculation\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use Math.Max(0, ...) on computed counts","Use checked arithmetic for remaining-length computations","Skip hashing calls when there are zero bytes to process"],"tags":["io","compression","argument-validation"],"backgroundTag":"argument-out-of-range","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}