stephen/nodetunes

Crash in debug method on content-length: 0

Opened this issue · 3 comments

The debug method on line 233 of rtspmethods.js seems to assume too much about a general request object:

debug('uncaptured SET_PARAMETER method: %s', req.content.toString().trim());

iTunes on iOS 9.2 issued the following request when streaming a file with no accompanying artwork:

received method SET_PARAMETER (CSeq: 6)
{ 'rtp-info': 'rtptime=839107797',
  'content-length': '0',
  'content-type': 'image/none',
  cseq: '6',
  'dacp-id': '___redacted___',
  'active-remote': '___redacted___',
  'user-agent': 'AirPlay/267.3' }

I believe the zero-length content led req.content to be undefined, giving the following error while formatting the debug message:

TypeError: Cannot read property 'toString' of undefined

The following fix worked, but may not be the detailed logging message originally intended:

debug('uncaptured SET_PARAMETER method: %s', req.getHeader('Content-Type'));

Thanks for looking at this issue, and thanks also for this excellent software.

Here were the versions I am using, from npm version:

{ airsonos: '0.2.5',
  npm: '3.3.12',
  ares: '1.10.1-DEV',
  http_parser: '2.6.0',
  icu: '56.1',
  modules: '47',
  node: '5.3.0',
  openssl: '1.0.2e',
  uv: '1.8.0',
  v8: '4.6.85.31',
  zlib: '1.2.8' }

I would suggest changing

debug('uncaptured SET_PARAMETER method: %s', req.content.toString().trim());

to:

 var debugString;
 if ("content" in req) {
   debugString = req.content.toString().trim();
 } else {
   debugString = req.getHeader('Content-Type');
 }
 debug('uncaptured SET_PARAMETER method: %s', debugString);

or something similar to capture both cases when you have content and when you do not. I can confirm this prevents airsonos from crashing out when it receives a stream with no image associated. My test case was going to tribeofnoise and playing a clip off the page (from safari) and sending to airplay.

This worked for me. Thanks Sinaloit.