{"record":{"id":"b3b28edbebdfbe31","repo":"wmjordan/PDFPatcher","slug":"0","errorCode":null,"errorMessage":"页面高度不可小于 0。","messagePattern":"页面高度不可小于 0。","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"App/Model/PaperSize.cs","lineNumber":47,"sourceCode":"\t\t\t\t\tAsLargestPage => SpecialPaperSize.AsLargestPage,\r\n\t\t\t\t\tAsSmallestPage => SpecialPaperSize.AsSmallestPage,\r\n\t\t\t\t\tAsFirstPage => SpecialPaperSize.AsFirstPage,\r\n\t\t\t\t\t_ => SpecialPaperSize.None,\r\n\t\t\t\t};\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t[XmlIgnore]\r\n\t\tpublic SpecialPaperSize SpecialSize { get; private set; }\r\n\r\n\t\tprivate float _Height;\r\n\t\t///<summary>获取或指定页面高度的值。</summary>\r\n\t\t[XmlAttribute(\"高度\")]\r\n\t\tpublic float Height {\r\n\t\t\tget => _Height;\r\n\t\t\tset {\r\n\t\t\t\tif (value < 0) {\r\n\t\t\t\t\tthrow new ArgumentException(\"页面高度不可小于 0。\");\r\n\t\t\t\t}\r\n\t\t\t\t_Height = value;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tprivate float _Width;\r\n\t\t///<summary>获取或指定页面宽度的值。</summary>\r\n\t\t[XmlAttribute(\"宽度\")]\r\n\t\tpublic float Width {\r\n\t\t\tget => _Width;\r\n\t\t\tset {\r\n\t\t\t\tif (value < 0) {\r\n\t\t\t\t\tthrow new ArgumentException(\"页面宽度不可小于 0。\");\r\n\t\t\t\t}\r\n\t\t\t\t_Width = value;\r\n\t\t\t}\r\n\t\t}\r\n\r","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/wmjordan/PDFPatcher/blob/4782bbd9ada850b56258f29999b7a1c9076c9b1b/App/Model/PaperSize.cs#L29-L65","documentation":"The PaperSize.Height setter rejects any negative value with ArgumentException. Height is serialized as the XML attribute '高度' (Height) and deserialized back via the same setter, so the guard fires both at runtime and when loading an XML info file. The check is a hard lower bound: zero is allowed (auto-height modes), negatives are not.","triggerScenarios":"Assigning a negative number to PaperSize.Height, or constructing a PaperSize(width, height) with a negative height argument, or loading an XML info document whose '高度' attribute parses to a negative float. Also triggered indirectly by scaling/rotation code that computes a new height and passes it through the constructor.","commonSituations":"A user-supplied or XML-stored page dimension contains a minus sign (e.g. a malformed info file edited by hand, or a locale/parse issue turning a decimal into a negative). Scaling logic in PageDimensionProcessor that multiplies dimensions and accidentally yields a negative result due to an inverted factor.","solutions":["Validate the height value is non-negative before assigning it to PaperSize.Height.","If loading from XML, sanitize or reject the '高度' attribute before deserialization.","Trace callers of the PaperSize(string, float, float) constructor to ensure no scaling/rotation path produces a negative height.","If auto-height semantics are intended, pass 0 instead of a negative sentinel."],"exampleFix":"// before\nvar p = new PaperSize(\"A4\", 595f, -842f);\n\n// after\nvar h = Math.Max(0f, computedHeight);\nvar p = new PaperSize(\"A4\", 595f, h);","handlingStrategy":"validation","validationCode":"float h = ComputeHeight();\nif (h < 0f) throw new ArgumentOutOfRangeException(nameof(h));\nvar p = new PaperSize(name, w, h); // Height setter is now safe","typeGuard":"static bool IsValidPaperDimension(float v) => v >= 0f;","tryCatchPattern":null,"preventionTips":["Wrap any computed dimension in Math.Max(0f, value) before constructing PaperSize.","Sanitize XML '高度' attributes before deserialization.","Unit-test PaperSize construction with boundary values 0 and -epsilon."],"tags":["validation","page-dimensions","argument","paper-size"],"backgroundTag":null,"analyzedSha":"4782bbd9ada850b56258f29999b7a1c9076c9b1b","analyzedAt":"2026-08-13T17:44:50.812Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}