Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions fbird_batch.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,14 +554,10 @@ int fbird_batch_add_impl(fbird_batch *fb_batch, zval *args, int argc)
/* BLOB ID as hex string "HHHHHHHH:LLLLLLLL" (17 characters)
* Format: 8 hex digits (high 32-bit), colon, 8 hex digits (low 32-bit)
* jane: #516 - was 13 chars (4 hex low), now 17 chars (8 hex low, full 32-bit)
/* BLOB ID as hex string "HHHHHHHH:LLLLLLLL" (17 characters)
* Format: 8 hex digits (high 32-bit), colon, 8 hex digits (low 32-bit)
* jane: #516 - was 13 chars (4 hex low), now 17 chars (8 hex low, full 32-bit)
* Example: "74292B00:7FFC"
*/
* Example: "74292B00:00007FFC" */
convert_to_string(b_var);

if (Z_STRLEN_P(b_var) == BLOB_ID_LEN &&
if (((Z_STRLEN_P(b_var) == BLOB_ID_LEN || Z_STRLEN_P(b_var) == BLOB_ID_LEN_LEGACY)) &&
_php_fbird_string_to_quad(Z_STRVAL_P(b_var), (ISC_QUAD *)data_ptr)) {
/* Valid BLOB ID parsed and written to message buffer */
break;
Expand Down Expand Up @@ -742,8 +738,8 @@ PHP_FUNCTION(fbird_batch_register_blob)
}

/* Validate and convert BLOB ID string to ISC_QUAD */
if (blob_id_len != BLOB_ID_LEN || !_php_fbird_string_to_quad(blob_id_str, &existing_blob)) {
_php_fbird_module_error("Invalid BLOB ID format (expected %d character hex string)", BLOB_ID_LEN);
if ((blob_id_len != BLOB_ID_LEN && blob_id_len != BLOB_ID_LEN_LEGACY) || !_php_fbird_string_to_quad(blob_id_str, &existing_blob)) {
_php_fbird_module_error("Invalid BLOB ID format (expected %d or %d character hex string)", BLOB_ID_LEN, BLOB_ID_LEN_LEGACY);
RETURN_FALSE;
}

Expand Down
2 changes: 1 addition & 1 deletion fbird_blobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ int _php_fbird_string_to_quad(char const *id, ISC_QUAD *qd)

if (sscanf(id, "%x:%x", &high_part, &low_part) == 2) {
qd->gds_quad_high = (ISC_LONG)high_part;
qd->gds_quad_low = (ISC_USHORT)low_part;
qd->gds_quad_low = (ISC_ULONG)low_part;
return 1;
}

Expand Down
4 changes: 2 additions & 2 deletions fbird_query_bind.c
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ int _php_fbird_bind(fbird_query *fb_query, zval *b_vars)

convert_to_string(b_var);

if (Z_STRLEN_P(b_var) != BLOB_ID_LEN ||
if ((Z_STRLEN_P(b_var) != BLOB_ID_LEN && Z_STRLEN_P(b_var) != BLOB_ID_LEN_LEGACY) ||
!_php_fbird_string_to_quad(Z_STRVAL_P(b_var), &buf[i].val.qval)) {

/* OO API only: create a blob, write the string into it, then bind by blob id (ISC_QUAD). */
Expand Down Expand Up @@ -1040,7 +1040,7 @@ int _php_fbird_bind(fbird_query *fb_query, zval *b_vars)
if (Z_TYPE_P(b_var) != IS_ARRAY) {
convert_to_string(b_var);

if (Z_STRLEN_P(b_var) != BLOB_ID_LEN ||
if ((Z_STRLEN_P(b_var) != BLOB_ID_LEN && Z_STRLEN_P(b_var) != BLOB_ID_LEN_LEGACY) ||
!_php_fbird_string_to_quad(Z_STRVAL_P(b_var), &buf[i].val.qval)) {

_php_fbird_module_error("Parameter %d: invalid array ID",i+1);
Expand Down
4 changes: 3 additions & 1 deletion php_fbird_includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,10 @@ ZEND_TSRMLS_CACHE_EXTERN()
* gds_quad_low is ISC_ULONG (32-bit unsigned) per firebird/impl/types_pub.h:194.
* BLOB_ID_MASK changed from %x:%hx (16-bit) to %x:%x (full 32-bit).
* Old 13-char IDs still parse correctly via _php_fbird_string_to_quad (uses %x:%x).
* BLOB_ID_LEN_LEGACY is for backwards-compat length checks in binding paths.
*/
#define BLOB_ID_LEN 17
#define BLOB_ID_LEN 17
#define BLOB_ID_LEN_LEGACY 13
#define BLOB_ID_MASK "%x:%x"

#define BLOB_INPUT 1
Expand Down
12 changes: 5 additions & 7 deletions src/Firebird/BlobId.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private function __construct(string $id, int $high, int $low)
* Create a BlobId from a string.
*
* Supports two formats:
* - Colon format: "HHHHHHHH:LLLL" (13 chars, standard from php-firebird extension)
* - Colon format: "HHHHHHHH:LLLLLLLL" (17 chars, standard from php-firebird extension)
* - Hex format: "0xHHHHHHHHHHHHHHHH" (18 chars, legacy)
*
* @param string $id BLOB ID string
Expand All @@ -119,7 +119,7 @@ public static function fromString(string $id): self

if (!self::isValidFormat($id)) {
throw new InvalidArgumentException(sprintf(
'Invalid BLOB ID format: "%s". Expected formats: "HHHHHHHH:LLLL" or "0xHHHHHHHHHHHHHHHH".',
'Invalid BLOB ID format: "%s". Expected formats: "HHHHHHHH:LLLLLLLL" or "0xHHHHHHHHHHHHHHHH".',
strlen($id) > 30 ? substr($id, 0, 30) . '...' : $id
));
}
Expand All @@ -132,12 +132,10 @@ public static function fromString(string $id): self
$low = hexdec($lowHex);
$normalized = sprintf('%08X:%08X', $high, $low);
} else {
// Hex format: "0xHHHHHHHHHHHHHHHH"
// Colon format uses high 32 bits + middle 16 bits (not last 16)
// Hex format: "0xHHHHHHHHLLLLLLLL" (16 hex digits = 64 bits)
$hex = substr($id, 2); // Remove "0x" prefix
$high = hexdec(substr($hex, 0, 8));
// For colon format, use middle 16 bits (positions 8-11, not 12-15)
$low = hexdec(substr($hex, 8, 4));
$high = hexdec(substr($hex, 0, 8)); // first 8 hex = high 32 bits
$low = hexdec(substr($hex, 8, 8)); // next 8 hex = low 32 bits
// Normalize to colon format (standard)
$normalized = sprintf('%08X:%08X', $high, $low);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/blobid_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ bool(false)
Test 10: Case insensitivity and format conversion
bool(true)
string(17) "abcdef01:00002345"
string(17) "abcdef01:00002345"
string(17) "abcdef01:23456789"

Test 11: Integration with fbird_blob functions
bool(true)
Expand Down
Loading