Skip to content

bluetape4k-dependencies 1.3.0 in Practice Part 4: Input Boundaries and Resource Safety

Small robotic workers inspect projects, exposed, aws, image, text, leader, graph, and javers module blocks beside a dependency BOM board in a 3D workbench illustration
Input-boundary bugs usually start with large files, long strings, strange encodings, or ambiguous failure responses, not with neat sample data.

Input edges are easy to underestimate. Small files, short strings, normal JSON, and hand-made test data all behave. Production sends something else:

  • an 80MB TIFF
  • an image with strange rotation metadata
  • a scan where OCR may or may not work
  • a 300,000-character search query
  • a string crafted to bypass blockword checks
  • text with broken encoding

OCR examples are useful, but the first operational question is where the file enters memory.

// Convenient for samples. Risky for large uploads.
val bytes = multipartFile.bytes
val text = ocr.read(bytes)

Large-file I/O should make size and streaming limits explicit before OCR options are tuned.

fun extractText(path: Path): OcrResult {
return fileSystem.source(path).buffer().use { source ->
imageReader
.read(source)
.resize(maxWidth = 2_000)
.normalizeForOcr()
.runOcr(language = "kor+eng")
}
}

The request path needs limits at every stage.

Input boundary flow from request receipt through low-cost checks, bounded decode, OCR or text processing, and a safe result, with invalid input rejected early
The boundary begins when the request arrives, not after decode. Check size and format first, then admit only bounded work.
StageLimit to apply
uploadrequest size, content type, timeout
temporary filedisk quota, cleanup policy
decodesupported formats, maximum pixel count
preprocessresize limit, native runtime failure handling
OCRlanguage, timeout, empty-result handling

An OCR API should distinguish user input problems from server/runtime problems.

sealed interface OcrFailure {
data object PayloadTooLarge : OcrFailure
data object UnsupportedFormat : OcrFailure
data object TimedOut : OcrFailure
data class RuntimeFailed(val cause: Throwable) : OcrFailure
}
FailureHTTP statusReason
file too large413The request exceeded an input limit.
unsupported format415The client must change the input.
OCR timeout504 or retryable failureProcessing exceeded its limit.
native runtime error500The server environment or native library needs inspection.

Tokenizers and language detectors are often attached behind HTTP endpoints. That makes input length a service policy, not only a library detail.

data class TextRequest(val text: String)
fun TextRequest.validate() {
require(text.length <= 10_000) { "text is too long" }
}

The expensive work should run after validation.

val normalized = normalizer.normalize(request.text)
val language = lingua.detect(normalized)
val tokens = koreanTokenizer.tokenize(normalized)

For search APIs, the empty or unresolved case is also a contract. Do not pretend language detection succeeded when it did not.

A blockword API usually starts as a boolean:

val allowed = blockwordChecker.isAllowed(input)

Production policy needs more questions:

  • Which fields are checked?
  • Is the original text logged?
  • Does the user see which word matched?
  • Are bypass strings normalized first?
  • How does an administrator update dictionaries?

The safer shape carries a decision and a redacted response boundary.

data class BlockwordDecision(
val allowed: Boolean,
val matchedPolicy: String?,
val reasonCode: String,
)
BoundaryQuestion
request sizeWhat is the maximum size this endpoint accepts?
decode/tokenize timeoutWhere does long processing stop?
memoryWhere does input become a full ByteArray or String copy?
status codeHow are user input problems separated from server problems?
error responseDoes raw input leak into responses or logs?
normalizationIs OCR/text/blockword normalization required before checking?
observabilityCan payload-too-large, timeout, and validation failures be seen as metrics?

dependencies 1.3.0 makes Image and Text APIs more usable, but the important lesson is still at the service edge. Before OCR quality or tokenizer accuracy, decide how large input can be, when processing stops, what gets logged, and which failure belongs to the client versus the server.

If you want the first import path, start with the usage guide.

Comments

Leave a note or reaction with your GitHub account.