From 8edbbdb09f24d26a2f900141fddc2b9d014f53b0 Mon Sep 17 00:00:00 2001
From: mohammadmseet-hue <mohammadmseet@gmail.com>
Date: Thu, 16 Apr 2026 02:54:30 +0200
Subject: [PATCH] fix: add length check to xmlURIEscapeStr in uri.c

Commit 538b2e38 fixed xmlBuildRelativeURISafe for the pattern where
xmlStrlen() returns 0 for strings longer than INT_MAX, but
xmlURIEscapeStr was not fixed. Without the check, len = 0 + 20, and
the write loop eventually overflows via int wrapping of the out counter.

Add a return NULL guard when xmlStrlen returns 0.
---
 uri.c | 2 ++
--- a/uri.c
+++ b/uri.c
@@ -1704,6 +1704,8 @@
     if (str[0] == 0)
 	return(xmlStrdup(str));
     len = xmlStrlen(str);
+    if (len == 0)
+        return(NULL);
 
     len += 20;
     ret = (xmlChar *) xmlMallocAtomic(len);
