feat(UTL_RAW): UTL_RAW.CAST_TO_RAW#1337
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughAdds an Oracle-compatible UTL_RAW package: a C function converting text to uppercase hex, a SQL package/spec exposing CAST_TO_RAW and endianness constants, build/meson wiring, and a regression test suite with expected outputs. ChangesUTL_RAW Oracle-Compatible Package
Sequence DiagramsequenceDiagram
participant Test as Test SQL
participant Pkg as UTL_RAW.CAST_TO_RAW
participant Helper as sys.utl_raw_cast_to_raw
participant CFunc as ora_utl_raw_cast_to_raw
Test->>Pkg: CAST_TO_RAW(varchar2)
Pkg->>Helper: forward (cast to text)
Helper->>CFunc: call C function
CFunc->>Helper: return hex text
Helper->>Pkg: return varchar2 result
Pkg->>Test: return result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. 🔧 OpenGrep (1.20.0)OpenGrep fatal error (exit code 2): [00.14][ERROR]: Error: exception Unix_error: No such file or directory stat contrib/ivorysql_ora/src/builtin_packages/utl_raw/utl_raw.c Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@contrib/ivorysql_ora/src/builtin_packages/utl_raw/utl_raw.c`:
- Around line 45-48: Before calling palloc to allocate result, check that the
computed size (VARHDRSZ + datalen * 2) does not exceed MaxAllocSize (or
otherwise allowable allocation threshold) and raise a controlled ereport/elog
error if it does; specifically, in the code that computes datalen and assigns
result (using VARHDRSZ, datalen, and palloc), compute the needed_size = VARHDRSZ
+ datalen * 2, verify needed_size <= MaxAllocSize (or use SizeIsValid/alloc size
helper used in the project), and call ereport(ERROR, ...) with a clear message
on overly large input when the check fails, only then call palloc(needed_size)
to assign result.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: aae3b8e1-469c-4f4d-9736-03306cb80cc8
📒 Files selected for processing (6)
contrib/ivorysql_ora/Makefilecontrib/ivorysql_ora/expected/utl_raw.outcontrib/ivorysql_ora/ivorysql_ora_merge_sqlscontrib/ivorysql_ora/sql/utl_raw.sqlcontrib/ivorysql_ora/src/builtin_packages/utl_raw/utl_raw--1.0.sqlcontrib/ivorysql_ora/src/builtin_packages/utl_raw/utl_raw.c
| datalen = VARSIZE_ANY_EXHDR(input); | ||
|
|
||
| result = palloc(VARHDRSZ + datalen * 2); | ||
| out = VARDATA(result); |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
cat -n contrib/ivorysql_ora/src/builtin_packages/utl_raw/utl_raw.c | head -60Repository: IvorySQL/IvorySQL
Length of output: 2143
🏁 Script executed:
rg "MaxAllocSize" --type c -B2 -A2Repository: IvorySQL/IvorySQL
Length of output: 44163
🏁 Script executed:
rg "VARHDRSZ.*datalen" --type c -B3 -A3Repository: IvorySQL/IvorySQL
Length of output: 3619
🏁 Script executed:
grep -n "if.*datalen.*>" contrib/ivorysql_ora/src/builtin_packages/utl_raw/utl_raw.cRepository: IvorySQL/IvorySQL
Length of output: 43
🏁 Script executed:
rg "encode\.c" --type c -A5 "MaxAllocSize - VARHDRSZ" | head -20Repository: IvorySQL/IvorySQL
Length of output: 125
Add an explicit size guard before output allocation.
Line 47 computes VARHDRSZ + datalen * 2 without checking MaxAllocSize. For very large inputs, palloc will fail with a low-level allocation error instead of a controlled function error. PostgreSQL's established practice is to pre-check allocation sizes to provide deterministic, user-friendly error messages.
💡 Suggested fix
data = VARDATA_ANY(input);
datalen = VARSIZE_ANY_EXHDR(input);
+ if (datalen > (MaxAllocSize - VARHDRSZ) / 2)
+ ereport(ERROR,
+ (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
+ errmsg("input is too long for UTL_RAW.CAST_TO_RAW")));
+
result = palloc(VARHDRSZ + datalen * 2);
out = VARDATA(result);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| datalen = VARSIZE_ANY_EXHDR(input); | |
| result = palloc(VARHDRSZ + datalen * 2); | |
| out = VARDATA(result); | |
| data = VARDATA_ANY(input); | |
| datalen = VARSIZE_ANY_EXHDR(input); | |
| if (datalen > (MaxAllocSize - VARHDRSZ) / 2) | |
| ereport(ERROR, | |
| (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), | |
| errmsg("input is too long for UTL_RAW.CAST_TO_RAW"))); | |
| result = palloc(VARHDRSZ + datalen * 2); | |
| out = VARDATA(result); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@contrib/ivorysql_ora/src/builtin_packages/utl_raw/utl_raw.c` around lines 45
- 48, Before calling palloc to allocate result, check that the computed size
(VARHDRSZ + datalen * 2) does not exceed MaxAllocSize (or otherwise allowable
allocation threshold) and raise a controlled ereport/elog error if it does;
specifically, in the code that computes datalen and assigns result (using
VARHDRSZ, datalen, and palloc), compute the needed_size = VARHDRSZ + datalen *
2, verify needed_size <= MaxAllocSize (or use SizeIsValid/alloc size helper used
in the project), and call ereport(ERROR, ...) with a clear message on overly
large input when the check fails, only then call palloc(needed_size) to assign
result.
Oracle compatible feature: UTL_RAW
#1057
Summary by CodeRabbit