Skip to content

Commit 0b0de1d

Browse files
Potential fix for code scanning alert no. 1894: Inconsistent lock sequence
To fix this problem, we should avoid locking on _syncLock in both methods when the instance method calls the static method. Because GetFont(Properties attributes) holds the lock while calling GetFont(...), which also tries to acquire the lock, there is a risk of deadlock or at least suboptimal locking. The best and most robust solution is to remove the lock (_syncLock) from one of these places to ensure the lock is only acquired once per operation. Since GetFont(Properties attributes) performs some parsing before calling the static method, and the core registry/caching logic is in the static method, it is preferable to only lock within the static method—meaning, remove the locking statement from the instance method (GetFont(Properties attributes)). Specifically: Remove the lock (_syncLock) block from the GetFont(Properties attributes) method (lines 281 and 416). Ensure that thread safety still exists by keeping the lock in the static method. No new imports or dependencies are necessary. Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 7d257ec commit 0b0de1d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/iTextSharp.LGPLv2.Core/iTextSharp/text/FontFactoryImp.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ public Font GetFont(Properties attributes)
278278
throw new ArgumentNullException(nameof(attributes));
279279
}
280280

281-
lock (_syncLock)
282-
{
281+
// Removed lock (_syncLock) to prevent inconsistent locking sequence
282+
283283
string fontname = null;
284284
var encoding = DefaultEncoding;
285285
var embedded = DefaultEmbedding;
@@ -413,7 +413,7 @@ public Font GetFont(Properties attributes)
413413
}
414414

415415
return GetFont(fontname, encoding, embedded, size, style, color);
416-
}
416+
417417
}
418418

419419
/// <summary>

0 commit comments

Comments
 (0)