[PECL-CVS] [pecl-database-pdo_oci] main: Fix memory leaks and data corruption issues in oci_statement.c + Minor test update

[email protected] (Sharad Chandran R)
Newsgroups php.pecl.cvs
Message-ID <[email protected]>
Author: Sharad Chandran R (sharadraju)
Date: 2025-12-30T16:37:01+05:30

Commit: https://github.com/php/pecl-database-pdo_oci/commit/6c89a5b76838f984c399f250d873df2adbd6bce1
Raw diff: https://github.com/php/pecl-database-pdo_oci/commit/6c89a5b76838f984c399f250d873df2adbd6bce1.diff

Fix memory leaks and data corruption issues in oci_statement.c + Minor test update

Changed paths:
  M  oci_statement.c
  M  tests/oci_success_with_info.phpt


Diff:

diff --git a/oci_statement.c b/oci_statement.c
index 68e275d..96ecfb8 100644
--- a/oci_statement.c
+++ b/oci_statement.c
@@ -604,6 +604,7 @@ static int oci_stmt_describe(pdo_stmt_t *stmt, int colno) /* {{{ */
 				oci_define_callback));
 	}
 
+	OCIDescriptorFree(param, OCI_DTYPE_PARAM);
 	return 1;
 } /* }}} */
 
@@ -693,13 +694,34 @@ static int oci_blob_flush(php_stream *stream)
 static int oci_blob_seek(php_stream *stream, zend_off_t offset, int whence, zend_off_t *newoffset)
 {
 	struct oci_lob_self *self = (struct oci_lob_self*)stream->abstract;
+	oraub8 loblen = 0;
 
-	if (offset >= PDO_OCI_LOBMAXSIZE) {
+	if (OCILobGetLength2(self->E->svc, self->E->err, self->lob, &loblen) != OCI_SUCCESS) {
 		return -1;
-	} else {
-		self->offset = (ub4) offset + 1;  /* Oracle LOBS are 1-based, but PHP is 0-based */
-		return 0;
 	}
+
+	zend_off_t new_offset = 0;
+	switch (whence) {
+		case SEEK_SET:
+			new_offset = offset;
+			break;
+		case SEEK_CUR:
+			new_offset = (zend_off_t)self->offset - 1 + offset;
+			break;
+		case SEEK_END:
+			new_offset = (zend_off_t)loblen + offset;
+			break;
+		default:
+			return -1;
+	}
+
+	if (new_offset < 0 || new_offset > (zend_off_t)loblen) {
+		return -1;
+	}
+
+	self->offset = (ub4)(new_offset + 1);  /* Oracle LOBS are 1-based, PHP 0-based */
+	*newoffset = new_offset;
+	return 0;
 }
 
 static const php_stream_ops oci_blob_stream_ops = {
diff --git a/tests/oci_success_with_info.phpt b/tests/oci_success_with_info.phpt
index 2526a00..f41ab3e 100644
--- a/tests/oci_success_with_info.phpt
+++ b/tests/oci_success_with_info.phpt
@@ -14,6 +14,7 @@ PDOTest::skip();
 --FILE--
 <?php
 
+require(getenv('PDO_TEST_DIR').'/pdo_test.inc');
 function connectAsAdmin(): PDO {
     return PDOTest::test_factory(getenv('PDO_OCI_TEST_DIR').'/common.phpt');
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.