{"id":17013935,"url":"https://github.com/john-paul-r/npgsql-repros","last_synced_at":"2025-07-16T17:33:53.366Z","repository":{"id":233626703,"uuid":"787588520","full_name":"John-Paul-R/npgsql-repros","owner":"John-Paul-R","description":null,"archived":false,"fork":false,"pushed_at":"2024-04-16T21:45:34.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-22T14:28:16.783Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/John-Paul-R.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-16T20:07:39.000Z","updated_at":"2024-04-16T20:09:03.000Z","dependencies_parsed_at":"2024-05-01T18:06:12.391Z","dependency_job_id":null,"html_url":"https://github.com/John-Paul-R/npgsql-repros","commit_stats":null,"previous_names":["john-paul-r/npgsql-repros"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/John-Paul-R/npgsql-repros","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/John-Paul-R%2Fnpgsql-repros","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/John-Paul-R%2Fnpgsql-repros/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/John-Paul-R%2Fnpgsql-repros/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/John-Paul-R%2Fnpgsql-repros/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/John-Paul-R","download_url":"https://codeload.github.com/John-Paul-R/npgsql-repros/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/John-Paul-R%2Fnpgsql-repros/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265527595,"owners_count":23782480,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T06:14:39.433Z","updated_at":"2025-07-16T17:33:53.347Z","avatar_url":"https://github.com/John-Paul-R.png","language":"C#","readme":"\n# npgsql repro: ArrayNullabilityMode.PerInstance buffer over-read\n\n## Usage\n\nstart the database via docker (the below will host on port 5433):\n\n```\ndocker build ./ -f ./Dockerfile -t npgsql-repros:nullable-array-overread\ndocker run -p5433:5432 npgsql-repros:nullable-array-overread\n```\n\nrun the dotnet project\n\n```\ndotnet run \n```\n\nobserve crash due to buffer over-read\n\n## Error Description\n\nThis particular error is caused by `PolymorphicArrayConverter\u003cT\u003e`'s `Read` method leading with 2 unchecked `ReadInt32` calls,\nwhich may read past the boundary of the working buffer.\n\npermalink: https://github.com/npgsql/npgsql/blob/058894067d33229fbef2f3bcafbfa75858fc60fb/src/Npgsql/Internal/Converters/ArrayConverter.cs#L631-L639\n\noffending code snippet:\n\n```csharp\n    public override TBase Read(PgReader reader)\n    {\n        _ = reader.ReadInt32();\n        var containsNulls = reader.ReadInt32() is 1;\n        reader.Rewind(sizeof(int) + sizeof(int));\n        return containsNulls\n            ? _nullableElementCollectionConverter.Read(reader)\n            : _structElementCollectionConverter.Read(reader);\n    }\n```\n\nI've personally patched this with\n\n```csharp\n    public override TBase Read(PgReader reader)\n    {\n        if (reader.ShouldBuffer(sizeof(int) + sizeof(int)))\n            reader.Buffer(sizeof(int) + sizeof(int));\n\n        _ = reader.ReadInt32();\n        var containsNulls = reader.ReadInt32() is 1;\n        reader.Rewind(sizeof(int) + sizeof(int));\n        return containsNulls\n            ? _nullableElementCollectionConverter.Read(reader)\n            : _structElementCollectionConverter.Read(reader);\n    }\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohn-paul-r%2Fnpgsql-repros","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjohn-paul-r%2Fnpgsql-repros","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjohn-paul-r%2Fnpgsql-repros/lists"}