YAACC - UPNP Client and Server
Loading...
Searching...
No Matches
de.yaacc.fcast.protocol.FCastText Class Reference

Text and number rules for what a receiver sends (everything from the network is untrusted): control characters are removed, long text is cut by code points, numbers are made finite and clamped, and a body nested too deep is refused before the JSON parser sees it (a recursive parser can overflow its stack on 16000 open brackets, which fit into a packet). More...

Collaboration diagram for de.yaacc.fcast.protocol.FCastText:
Collaboration graph

Static Public Member Functions

static String clean (String text, int maxCodePoints)
 
static double clamp (double value, double min, double max)
 
static boolean isAcceptableJson (String body)
 Is this body safe to hand to the platform's JSON parser? Android's org.json tokener is far more lenient than JSON (single-quoted strings, //, /* */ and # comments, ; and = as separators) and recurses without a limit, so a scan that only understands double-quoted strings can be fooled into counting too little nesting (a ' or a comment hides a ") and the parser then overflows its stack.
 
static boolean isNestedTooDeep (String body)
 

Static Public Attributes

static final int MAX_NAME = 60
 Names of receivers and apps.
 
static final int MAX_ERROR = 200
 Error texts of a receiver.
 
static final int MAX_URL = 2048
 URLs and MIME types from a receiver (shown, never fetched).
 
static final int MAX_DEPTH = 16
 The deepest nesting of arrays and objects in a body that is parsed (a message of protocol v3 has 3).
 

Detailed Description

Text and number rules for what a receiver sends (everything from the network is untrusted): control characters are removed, long text is cut by code points, numbers are made finite and clamped, and a body nested too deep is refused before the JSON parser sees it (a recursive parser can overflow its stack on 16000 open brackets, which fit into a packet).

Pure.

Member Function Documentation

◆ clamp()

static double de.yaacc.fcast.protocol.FCastText.clamp ( double value,
double min,
double max )
static
Returns
the value, or min / max if outside; NaN becomes min

Referenced by de.yaacc.fcast.FCastPlayRequests.build().

Here is the caller graph for this function:

◆ clean()

static String de.yaacc.fcast.protocol.FCastText.clean ( String text,
int maxCodePoints )
static
Returns
the text without control characters (every character below 0x20, 0x7f to 0x9f, and the line and paragraph separators) and without lone surrogates, trimmed and cut to at most maxCodePoints code points; null stays null

Referenced by de.yaacc.fcast.FCastSheetTrace.add(), de.yaacc.fcast.discovery.FCastServiceTxt.parse(), de.yaacc.fcast.discovery.FCastStoredReceivers.replaceAll(), and de.yaacc.fcast.discovery.FCastDirectory.serviceFound().

Here is the caller graph for this function:

◆ isAcceptableJson()

static boolean de.yaacc.fcast.protocol.FCastText.isAcceptableJson ( String body)
static

Is this body safe to hand to the platform's JSON parser? Android's org.json tokener is far more lenient than JSON (single-quoted strings, //, /* */ and # comments, ; and = as separators) and recurses without a limit, so a scan that only understands double-quoted strings can be fooled into counting too little nesting (a ' or a comment hides a ") and the parser then overflows its stack.

So this scan is strict: outside double-quoted strings only whitespace, the structure characters { } [ ] , : and the characters of numbers and of true, false, null are allowed; and the nesting is limited to MAX_DEPTH.

◆ isNestedTooDeep()

static boolean de.yaacc.fcast.protocol.FCastText.isNestedTooDeep ( String body)
static
Returns
true if the body has more than MAX_DEPTH levels of arrays and objects (brackets in strings do not count)

The documentation for this class was generated from the following file: