php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #77810
Patch dbase3-Itype.7 revision 2019-03-27 16:15 UTC by alter at alter dot org dot ua

Patch dbase3-Itype.7 for dbase Bug #77810

Patch version 2019-03-27 16:15 UTC

Return to Bug #77810 | Download this patch
Patch Revisions:

Developer: alter@alter.org.ua

--- dbase.c.orig	2017-09-21 20:27:24.000000000 +0300
+++ dbase.c	2019-03-14 00:52:23.539248356 +0200
@@ -447,6 +447,7 @@
 	long overflow_test;
 	int errno_save;
 	DBase_TLS_VARS;
+	int decoded_len;
 
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lz", &dbh_id, &record) == FAILURE) {
 		WRONG_PARAM_COUNT;
@@ -472,13 +473,26 @@
 	fnp = NULL;
 	for (cur_f = dbf; cur_f < &dbf[dbht->db_nfields]; cur_f++) {
 		/* get the value */
-		str_value = (char *)emalloc(cur_f->db_flen + 1);
+		if(cur_f->db_flen_decoded || cur_f->db_type == 'I') {
+			/* handle binary data */
+			decoded_len = cur_f->db_flen_decoded;
+		} else {
+			decoded_len = cur_f->db_flen;
+		}
+		str_value = (char *)emalloc(decoded_len + 1);
 
-		if(cursize <= (unsigned)cur_f->db_flen) {
-			cursize = cur_f->db_flen + 1;
+		if(cursize <= (unsigned)decoded_len) {
+			cursize = decoded_len + 1;
 			fnp = erealloc(fnp, cursize);
 		}
-		snprintf(str_value, cursize, cur_f->db_format, get_field_val(data, cur_f, fnp));
+		if(cur_f->db_flen_decoded || cur_f->db_type == 'I') {
+		        //printf("%d,%d %s\n", cursize, cur_f->db_flen_decoded, cur_f->db_format);
+  		        //snprintf(str_value, cursize, "%d", *((long*)get_field_val(data, cur_f, fnp)));
+  		        snprintf(str_value, cursize, "%d", get_long(get_field_val(data, cur_f, fnp)));
+		        //printf("*** %d ***\n", *((long*)get_field_val(data, cur_f, fnp)));
+		} else {
+  		        snprintf(str_value, cursize, cur_f->db_format, get_field_val(data, cur_f, fnp));
+		}
 
 		/* now convert it to the right php internal type */
 		switch (cur_f->db_type) {
@@ -490,7 +504,8 @@
 					add_assoc_string(return_value, cur_f->db_fname, str_value);
 				}
 				break;
-			case 'I':	/* FALLS THROUGH */
+			case 'I':
+				/* FALL THROUGH, 4-byte integer is already converted to string */
 			case 'N':
 				if (cur_f->db_fdc == 0) {
 					/* Large integers in dbase can be larger than long */
@@ -897,7 +912,7 @@
 		}
 		
 		/* length of field */
-		add_assoc_long(&row, "length", cur_f->db_flen);
+		add_assoc_long(row, "length", cur_f->db_flen_decoded ? cur_f->db_flen_decoded : cur_f->db_flen);
 		
 		/* number of decimals in field */
 		switch (cur_f->db_type) {
--- dbf_rec.c.orig	2019-03-14 00:50:38.559529953 +0200
+++ dbf_rec.c	2019-03-14 00:53:50.893990267 +0200
@@ -152,7 +152,12 @@
 	if ( !cp )
 		cp = (char *)malloc(flen + 1);
 	if ( cp ) {
-		strlcpy(cp, &rp[fldp->db_foffset], flen + 1);
+		if(fldp->db_flen_decoded) {                      
+			/* copy binary data AS-IS */             
+			memcpy(cp, &rp[fldp->db_foffset], flen); 
+		} else {                                         
+			strlcpy(cp, &rp[fldp->db_foffset], flen + 1);
+		}                                                
 	}
 	return cp;
 }
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC