Skip to content

[fix] Prevent schema validation nil dereferences - #495

Open
serein6174 wants to merge 1 commit into
LDFLK:mainfrom
serein6174:fix/nil-input-validation
Open

[fix] Prevent schema validation nil dereferences#495
serein6174 wants to merge 1 commit into
LDFLK:mainfrom
serein6174:fix/nil-input-validation

Conversation

@serein6174

@serein6174 serein6174 commented Jul 31, 2026

Copy link
Copy Markdown

Summary

Prevent schema validation from panicking when it receives incomplete scalar or map property schemas.

Problem

ValidateSchema could dereference nil schema metadata in the following cases:

  • A scalar schema has no TypeInfo.
  • A missing map property has a nil property schema.
  • A missing map property has a schema with no TypeInfo.

These malformed schemas caused a runtime panic instead of returning a validation error.

Changes

  • Return a descriptive error when scalar TypeInfo is nil.
  • Validate missing map property schemas before checking nullability.
  • Add regression tests for all three nil dereference paths.

Testing

go test ./pkg/schema -run 'TestValidateSchemaRejects' -v
go test ./pkg/...
···

All package tests pass.

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

* **Bug Fixes**
  * Improved schema validation error reporting for missing type information.
  * Map validation now clearly identifies properties without schemas or type definitions.
  * Prevented invalid scalar schemas from passing validation.

* **Tests**
  * Added coverage for invalid scalar and map schema configurations.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Return descriptive errors when scalar or map schemas contain missing type information instead of allowing nil pointer dereferences.

Add regression tests for malformed scalar and map property schemas.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@CLAassistant

CLAassistant commented Jul 31, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3105d9b9-e9fd-417a-9641-94196563be1c

📥 Commits

Reviewing files that changed from the base of the PR and between b85611f and 57c3a5a.

📒 Files selected for processing (2)
  • opengin/core-api/pkg/schema/utils.go
  • opengin/core-api/pkg/schema/utils_test.go

📝 Walkthrough

Walkthrough

Schema validation now rejects missing scalar type information and reports missing map property schemas or type information. Tests cover these cases and assert the exact validation errors.

Changes

Schema validation

Layer / File(s) Summary
Add validation guards and tests
opengin/core-api/pkg/schema/utils.go, opengin/core-api/pkg/schema/utils_test.go
validateScalarValue returns an error when TypeInfo is nil. Map validation reports nil property schemas and nil property type information before checking key nullability. Tests assert the exact errors.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: preventing nil dereferences during schema validation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants