{"record":{"id":"8357b60936c84e2e","repo":"wmjordan/PDFPatcher","slug":"0-8357b6","errorCode":null,"errorMessage":"页面宽度不可小于 0。","messagePattern":"页面宽度不可小于 0。","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"App/Model/PaperSize.cs","lineNumber":60,"sourceCode":"\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\n\t\tpublic PaperSize() { }\r\n\r\n\t\tpublic PaperSize(float width, float height) : this(null, width, height) {\r\n\t\t}\r\n\r\n\t\tpublic PaperSize(string paperName, float width, float height) {\r\n\t\t\tPaperName = paperName;\r\n\t\t\tWidth = width;\r\n\t\t\tHeight = height;\r\n\t\t}\r\n\r\n\t\tinternal PaperSize Scale(float xFactor, float yFactor) {\r\n\t\t\treturn new PaperSize(PaperName, Width * xFactor, Height * yFactor);\r","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/wmjordan/PDFPatcher/blob/4782bbd9ada850b56258f29999b7a1c9076c9b1b/App/Model/PaperSize.cs#L42-L78","documentation":"The PaperSize.Width setter rejects any negative value with ArgumentException. Width is serialized as XML attribute '宽度' (Width) and round-trips through the same setter. Zero is permitted (used by special auto-width modes), negatives are not.","triggerScenarios":"Assigning a negative number to PaperSize.Width, constructing a PaperSize(width, height) with a negative width, or deserializing an XML info document whose '宽度' attribute is negative. Also reached via PaperSize.Scale or RotatePage-derived computations that feed a negative width back through the constructor.","commonSituations":"Hand-edited XML info file with a malformed width value; a unit-conversion or scaling factor that flips the sign; rotation logic in PageDimensionProcessor swapping width/height when one was already negative.","solutions":["Validate the width value is non-negative before assigning it to PaperSize.Width.","Sanitize the '宽度' attribute in XML before loading if the source is untrusted.","Audit Scale() callers and rotation code paths that construct new PaperSize instances to ensure positive inputs.","Pass 0 rather than a negative sentinel for auto-width special sizes."],"exampleFix":"// before\nsize = new PaperSize(name, size.Height, size.Width); // size.Width may be negative\n\n// after\nsize = new PaperSize(name, size.Height, Math.Max(0f, size.Width));","handlingStrategy":"validation","validationCode":"float w = ComputeWidth();\nif (w < 0f) throw new ArgumentOutOfRangeException(nameof(w));\nvar p = new PaperSize(name, w, h);","typeGuard":"static bool IsValidPaperDimension(float v) => v >= 0f;","tryCatchPattern":null,"preventionTips":["Wrap computed widths in Math.Max(0f, value).","Validate XML '宽度' attributes before loading.","Audit rotation/scaling paths that swap width and height."],"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"}